duanou2526 2016-08-13 07:48
浏览 210
已采纳

尽管进行了所有设置,PHP邮件函数仍返回false

I am a newbie in PHP, so all i know is actually from the forums. These are the settings i made in my php.ini file

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = engr.atiq19@gmail.com
sendmail_path = "\"C:\xamppnew\sendmail\sendmail.exe\" -t"
;sendmail_path = "C:\xamppnew\mailtodisk\mailtodisk.exe"

These are the changes made in sendmail.ini file

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=engr.atiq19@gmail.com
auth_password=************
force_sender=engr.atiq19@gmail.com

And here is the code I am using to send the mail

$to = "engr.atiq19@gmail.com";
$myemail = "engr.atiq19@gmail.com";    
$email_subject = "Contact form submission: $name";
$email_body = "my message";
$headers = "From: $myemail
";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
header('Location: ../index-alt2.html?t="done successfully"');
  • 写回答

1条回答 默认 最新

  • dqz13288 2016-08-13 09:17
    关注

    I would recommend using PHPMailer to send email from PHP. Here's the steps to accomplish this.

    1. Go to the Github repository.
    2. Download the ZIP.
    3. Extract it in your public_html directory.
    4. include '/path/to/PHPMailer/PHPMailerAutoload.php'; at the top of your PHP script.
    5. Get the values from the HTML form like you normally would.

    Here's an example...

    index.html
    
    <form action="index.php" method="post">
        <input type="email" name="email">
        <input type="text" name="name">
        <input type="text" name="subject">
        <input type="text" name="message">
    </form>
    
    index.php
    
    include '/path/to/PHPMailer/PHPMailerAutoload.php';
    
    $email = $_POST['email'];
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    
    $mail = new PHPMailer;
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'localhost'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'username'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, "ssl" also accepted
    $mail->Port = 587; // TCP port to connect to
    
    $mail->setFrom('your email', 'your name'); // from
    $mail->addAddress($email, $name); // to
    $mail->isHTML(true); // if html
    
    $mail->Subject = $subject;
    $mail->Body = $message; //HTML
    
    if($mail->send()){
        echo 'Mail sent!';
    }
    else {
        echo 'Mail failed!';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题