简体   繁体   中英

Sending mail failed in php

I am trying to send email using mail function in php:

$subject = 'testing';
$email = 'test@gmail.com';
$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?

$subject = 'testing';
$email = 'test@gmail.com';
$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="info@mypropick.com"; 
$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!";
}  

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: valid@email.com" . "\r\n";

'From' must be a valid email address

You forgot a closing apostrophe in the code

$message = 'test message;

should be

$message = 'test message'; 

SMTP Error 501 : Syntax error in parameters or arguments (eg invalid email address)

The command was correct and recognized, but the parameters (the arguments, eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM