【问题标题】:Send HTML Email using PHP - Not working when using email.2015@gmail.com?使用 PHP 发送 HTML 电子邮件 - 使用 email.2015@gmail.com 时不起作用?
【发布时间】:2015-12-05 13:12:18
【问题描述】:

我正在使用这个基本的 php 代码发送一个 html 电子邮件。

当我使用email@email.com 作为解决脚本工作的地址时。 但是,当我尝试使用 email.2015@gmail.com 时,脚本会说:

Parse error: syntax error, unexpected '@' in /home/u925912002/public_html/send_email.php on line 3

我的代码:

<?php

$to = ‘email.2015@gmail.com’;

$subject = 'I need to show html'; 

$from ='example@example.com'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
  $headers .= "Content-type: text/html\r\n"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

?>

请有人告诉我我做错了什么。谢谢

【问题讨论】:

  • 为什么您在电子邮件中的引号看起来不一样?

标签: php html email


【解决方案1】:

对于您最近结束的问题:https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working

试试这个:

$headers .= "From: Your Name &lt;$from&gt;\r\n";

您也可以添加5th mail parameter

mail($to, $subject, $body, $headers, '-finfo@userforum.com')

这些标题对我有用:

$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";

【讨论】:

    【解决方案2】:

    你正在使用撇号(')而不是引号(')

    试试这个 -

    $to = 'email.2015@gmail.com';
    

    而不是这个 -

    $to = ‘email.2015@gmail.com’;
    

    【讨论】:

      猜你喜欢
      • 2015-02-23
      • 2011-06-06
      • 1970-01-01
      • 2015-07-20
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 2010-12-19
      相关资源
      最近更新 更多