dopod0901 2014-05-17 11:02
浏览 7
已采纳

php邮件无法发送[重复]

This question already has an answer here:

Im using a mailing form but the mail cannot be sent to gmail inbox !!

here is the code i'm using:

<?php
if (isset($_POST['send'])) {
    $name    = $_POST['name'];
    $email   = $_POST['email'];
    $message = $_POST['message'];       

    $emailTo = 'example@gmail.com';
    $subject = 'Sujet:  '.$name;

    $body = "Full Name: $name 

  Message: $message 

 Sent by : $email";
    $headers = 'De: ' .' <'.$email.'>' . "
";

    if(mail($emailTo, $subject, $body, $headers)){  
         echo   "Success";

    }else{  
          echo "Error";

    }
}

?>

</div>
  • 写回答

2条回答 默认 最新

  • donglanzhan7151 2014-05-17 11:16
    关注

    Try This code:

    $name    = $_POST['name'];
    $email   = $_POST['email'];
    $message = $_POST['message'];
    
    $email_to = "example@email.com";
    $email_subject = "Email for: ".$name;
    
    $headers = $headers = 'From: '.$email."
    ".
           'BCC: '.$email_to_bcc."
    " .
           'X-Mailer: PHP/' . phpversion() . "
    " .
           "MIME-Version: 1.0
    " .
           "Content-Type: text/html; charset=utf-8
    " .
           "Content-Transfer-Encoding: 8bit
    
    ";
    
    if (mail($email_to, $email_subject, $message, $headers)) {
        echo "Mail sent";
    }
    

    Of course your server has to be able to send emails through PHP mail function. Best to set up sending mails through SMTP: Use this script: https://github.com/Synchro/PHPMailer Easy to set up and works great.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图