无法使用php mail()函数发送邮件

时间:2017-01-04 11:00:08

标签: php email

http://webprojects.co/dev_wed/mail.php尝试使用此脚本从服务器发送邮件,但我无法从服务器发送邮件

<?php
$to = "test@gmail.com";
$subject = "HTML email";

$message = "
<html>
  <head>
    <title>HTML email</title>
  </head>
  <body>
  <p>This email contains HTML Tags!</p>
      <table>
        <tr>
         <th>Firstname</th>
         <th>Lastname</th>
        </tr>
        <tr>
          <td>John</td>
          <td>Doe</td>
        </tr>
      </table>
  </body>
  </html>
";


$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webprojects@webprojects.com>' . "\r\n";
$headers .= 'Cc: webprojects@webprojects.com' . "\r\n";

$result = mail($to,$subject,$message,$headers);

if(!$result) {   
     echo "Error";   
} else {
    echo "Success";
}
?>
尝试使用php mail()函数

发送电子邮件时始终显示错误

1 个答案:

答案 0 :(得分:1)

您是在线还是通过localhost测试代码? mail()函数在没有SMTP的localhost中不起作用。