0

我正在尝试使用 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!";
}  

我遇到以下错误:

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

我可能猜测该错误是由于未设置在 php 中发送电子邮件所需的配置。我应该做什么,或者我必须更改 php.ini 文件,但它无法访问。请问有什么解决办法吗?

4

4 回答 4

3
$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!";
}  
于 2013-03-15T04:52:18.360 回答
0

第 3 行中缺少引号“'”

$message = 'test message' ;   
                        ^

尝试 :

$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'必须是一个有效的E-mail地址

于 2013-03-15T04:28:32.123 回答
0

您忘记了代码中的结束撇号

$message = 'test message;

应该

$message = 'test message'; 
于 2013-03-15T04:28:55.187 回答
0

SMTP 错误 501:参数或参数中的语法错误(例如无效的电子邮件地址)

该命令正确且可识别,但参数(参数,例如电子邮件地址)无效。例如,您尝试使用无效的电子邮件地址作为电子邮件地址中sender\@domain.com不允许"\"的。

http://info.webtoolhub.com/kb-a15-smtp-status-codes-smtp-error-codes-smtp-reply-codes.aspx

于 2013-03-15T04:42:58.130 回答