donglie7778 2013-03-15 04:26
浏览 49
已采纳

在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' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$headers .= "From: The test site" . "
";

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?

  • 写回答

4条回答 默认 最新

  • dongyi2083 2013-03-15 04:52
    关注
    $subject = 'testing';
    $email = 'test@gmail.com';
    $message = 'test message';          
    $headers  = 'MIME-Version: 1.0' . "
    ";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    $headers .= "From: The test site" . "
    ";
    
    
    $to=$toEmail;
    $subject=$sub;
    $from="info@mypropick.com"; 
    $headers = "MIME-Version: 1.0
    ";
    $headers .= "Content-type: text/html; charset=iso-8859-1
    ";
    $headers .= "From: <".$from.">
    ";
    $headers .= "X-Priority: 1
    ";
    $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!";
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?