【问题标题】:Why isn't my gmail or yahoo email accounts receiving mail when I use this PHP mail function为什么我使用此 PHP 邮件功能时,我的 gmail 或 yahoo 电子邮件帐户收不到邮件
【发布时间】:2012-09-19 22:55:45
【问题描述】:

带有标题的 send_mail 函数。是什么阻止了这个被接收。我知道它至少有时有效,我的工作电子邮件接收它就好了。

另一件可能值得注意的事情: - 使用不同的 ssl 页面,该功能确实正确发送到 gmail - 在这个完全独立的域上,它不是。

function send_mail($from,$fromName,$to,$object,$bodyText,$bodyHtml){
    $site = "mywebsite.ca";
    $from = $fromName." <".$from.">";
    $limite = "_----------=_parties_".md5(uniqid (rand()));

    $header  = "Reply-to: ".$from."\n";
    $header .= "From: ".$from."\n";
    $header .= "X-Sender: <".$site.">\n";
    $header .= "X-Mailer: PHP\n";
    $header .= "X-auth-smtp-user: ".$from." \n";    
    $header .= "X-abuse-contact: ".$from." \n"; 
    $header .= "Date: ".date("D, j M Y G:i:s O")."\n";
    $header .= "MIME-Version: 1.0\n";
    $header .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";

    $message = "";
    $message .= "--".$limite."\n";
    $message .= "Content-Type: text/plain\n";
    $message .= "charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= $bodyText;

    $message .= "\n\n--".$limite."\n";
    $message .= "Content-Type: text/html; ";
    $message .= "charset=\"iso-8859-1\"; ";
    $message .= "Content-Transfer-Encoding: 8bit;\n\n";
    $message .= $bodyHtml;

    $message .= "\n--".$limite."--";
    if(mail($to, $object, $message, $header)) return true;
    else return false;
}

【问题讨论】:

  • 可能是邮件被扔到了垃圾邮件文件夹。您检查垃圾邮件文件夹了吗?
  • 不,垃圾邮件文件夹中没有任何内容
  • 这很奇怪,因为我以前用它发送到 gmail 并且它工作得很好,包括 html。

标签: php gmail mime


【解决方案1】:

为什么要将 TextHTML 内容类型合并到同一个变量中?

$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain\n";
$message .= "charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $bodyText;

$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;

只使用其中任何一种

喜欢而不是上面

$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;

【讨论】:

  • 其实$bodyText$bodyHtml是不同的变量。同时使用这两种方法可以让收件人选择显示纯文本或 html。
  • $bodytext 和 $bodyhtml 是不同的,但是是一个变量,它连接了 $message html 和文本
【解决方案2】:
 if(mail($to, $object, $message, $header)) return true;
    else return false;

将邮件发送到您的电子邮件的代码尝试调试它,特别是 $to 变量中的所有变量,因为它是您的电子邮件,将发送消息。

试试这个

if(mail($to,$object,$message,$header)){
      //echo all
}
else{
      //echo mssage not submit
}

【讨论】:

  • 这将区分 maill 函数是否已定义运行添加发送消息。
  • 该功能适用​​于我的工作电子邮件地址,但不适用于 gmail 或 yahoo!就此而言
  • ini_set("sendmail_from", $email_from);尝试为标题添加..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 2021-01-31
  • 2010-11-25
  • 2018-02-03
  • 1970-01-01
相关资源
最近更新 更多