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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测