dougu4704 2017-09-04 05:12
浏览 49

php mail()函数无法使用phpmailer工作

<?php

require 'PHPMailerAutoload.php';
//echo !extension_loaded('openssl')?"Not Available":"Available <br/>";

$name = $_POST['username'];
$email = $_POST['email'];
$number = $_POST['phone'];
$profession = $_POST['profession'];

$to = 'example@gmail.com';
$subject = 'user registration';
$phone = "phone number:".$number;

$message = "client details:"."
"."Name:".$name."
"."email:".$email."
"."phone number:".$number."
"."profession:".$profession;

$headers = "From:".$email;

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               

$mail->isSMTP();                                      
$mail->Host = 'ssl://smtp.gmail.com';      
$mail->SMTPAuth = true;                            
$mail->Username = 'example@gmail.com';                      
$mail->Password = 'password';                           
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

$mail->setFrom($email, $name);

$mail->Subject = $subject;
$mail->Body    = $message;

if($mail->send()) {
    header("Location: ../../thankyouNew.html");
}
else {
    header("Location: ../../somethingWrong.html");
}

?>

code is executing else block, i want to send mail to example@gmail.com and return user to the thankyou.html page after the mail function is executed.I am new to this php and i would highly appreciate the help thank you in advance. forget the below lines........

  • 写回答

1条回答 默认 最新

  • dongrong5189 2017-09-04 05:19
    关注

    You don't actually specify where you want to send the email. You need to use the addAddress() method, as shown below. This method requires one parameter, but you may supply two - in the same way your setFrom() method has; first the target address, then an optional display name.

    $mail = new PHPMailer;
    
    // ...
    
    $mail->setFrom($email, $name);
    $mail->addAddress($to); // Add this method to specify a recipient 
    $mail->Subject = $subject;
    $mail->Body    = $message;
    if($mail->send()) {
        // ...
    }
    // ...
    
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站