dpwdldgn43486 2015-10-29 05:04
浏览 79

为什么Php Mailer不发送电子邮件如果发件人是Yahoo Mail

I am sending e-mail using php mailer. But if the sender is yahoo email address then it's not sending the email. why ?

I am using following code :

  require 'PHPMailerAutoload.php'; 
  $mail = new PHPMailer(true);
  try {
      //Set who the message is to be sent from
      $mail->setFrom("$email", "$name");  // yahoo mail address        
      //Set an alternative reply-to address
      //$mail->addReplyTo('replyto@example.com',  "$name");
      //Set who the message is to be sent to
      $mail->addAddress('receiver email adddress', 'Name');
      //Set the subject line
      $mail->Subject = "$subject";
      //Read an HTML message body from an external file, convert referenced images to embedded,
      //and convert the HTML into a basic plain-text alternative body
      $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
      //Replace the plain text body with one created manually
      $mail->AltBody = 'This is a plain-text message body';
      //Attach an image file
      //$mail->addAttachment('images/phpmailer_mini.png');
      //send the message
      //Note that we don't need check the response from this because it will throw an exception if it has trouble
      $mail->send();
      echo "Message sent! = $email";
  } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
  } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
  }
  • 写回答

1条回答 默认 最新

  • duannaiying9662 2015-10-29 09:36
    关注

    As it stands you're sending using mail() (PHPMailer's default behaviour) via your own local mail server, which is not Yahoo.

    If you're sending from a Yahoo address, but are not sending through a yahoo server, your messages will fail SPF checks since Yahoo has a very strict policy.

    So you need to either call isSMTP() and set Host to a yahoo SMTP server (and set up appropriate auth, base your code on the gmail example provided with PHPMailer as it's very similar), or change your from address to one that reflects the server you're really sending from, or whose SPF record allows your server to be a mail source.

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题