Reputation: 1014
I am trying to send email using mail function in php:
$subject = 'testing';
$email = '[email protected]';
$message = 'test message';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: The test site" . "\r\n";
if (mail($email, $subject, $message, $headers)) {
$data['msg']="Message send successfully";
}
else {
$data['msg']="Please try again, Message could not be sent!";
}
I Encounter following error:
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: SMTP server response: 501 Syntax error in parameters or arguments
Filename: sendemail.php
Line Number: 40
I might guess that error was due to not setting configuration required for sending email in php. What should I need to do or I have to change in php.ini file but it's not accesible. Any solution please?
Upvotes: 0
Views: 10441
Reputation: 78
$subject = 'testing';
$email = '[email protected]';
$message = 'test message';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: The test site" . "\r\n";
$to=$toEmail;
$subject=$sub;
$from="[email protected]";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: <".$from.">\n";
$headers .= "X-Priority: 1\n";
$message='<div style=" width:700px; margin:0 auto; border:1px solid #e2e2e2; padding:20px;">
<h3>MYPROPICK Services:</h3>'.$msg.'</div>';
$message .= "<br/>Regards <br />MYPROPICK.COM";
if (mail($to, $subject, $message, $headers )) {
$data['msg']="Message send successfully";
}
else {
$data['msg']="Please try again, Message could not be sent!";
}
Upvotes: 3
Reputation: 27354
The command was correct and recognized, but the parameters (the arguments, e.g. email address) were not valid. For example you try to use invalid email address as
sender\@domain.com
and as"\"
is not allowed in email addresses.
http://info.webtoolhub.com/kb-a15-smtp-status-codes-smtp-error-codes-smtp-reply-codes.aspx
Upvotes: 0
Reputation: 5809
a quotes " ' " missed in 3rd line
$message = 'test message' ;
^
try :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: [email protected]" . "\r\n";
'From'
must be a valid email address
Upvotes: 0
Reputation: 2001
You forgot a closing apostrophe in the code
$message = 'test message;
should be
$message = 'test message';
Upvotes: 0