php中的邮件配置出错

时间:2018-05-08 12:04:07

标签: email phpmailer

我设计了我的网站并托管在我的amazon ec2实例上,我在godaddy(www.mydomain.com)购买了我的域名。现在我想在网站的联系表单页面中进行邮件配置..在我的代码下面,我我不知道我在哪里弄错了代码?

  <?php 
        if(isset($_REQUEST['submit'])) {
            try {
                $name = $_POST['name'];

                echo "<script type='text/javascript'>alert('$name')</script>";

                $email = $_POST['email'];
                echo "<script type='text/javascript'>alert('$email')</script>";

                 $subject = $_POST['subject'];
                 echo "<script type='text/javascript'>alert('$subject')</script>";

                 $message = $_POST['message'];
                 echo "<script type='text/javascript'>alert('$message')</script>";

                 $response ="";
                 $body ="<div style='font-size:18px'>
                     <b>Name</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : $name  <br />
                     <b>Email address</b> &nbsp;&nbsp;&nbsp;&nbsp;: $email  <br />
                     <b>Message</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : $message <br />
                </div>"


                $to = "XXXXX@gmail.com";

                require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.phpmailer.php');
                require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.smtp.php');

                $mail = new PHPMailer(true);
                //$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
                // echo $res;

                $mail->IsSMTP();

                $mail->Host      = "email-smtp.us-east-1.amazonaws.com";
                $mail->SMTPDebug = true;
                $mail->SMTPAuth  = true; // Auth Type
                $mail->Port      = 25;

                $mail->IsSendmail(); 
                //$mail->SMTPSecure = "ssl";

                $mail->Username = "support@mydomain.com";
                $mail->Password = "******";
                $mail->Sender   = "supportexample@mydomain.com";
                $mail->From     = "supportexample@mydomain.com";

                $mail->AddReplyTo($email);

                $mail->FromName = "Example";
                $mail->AddAddress($to);
                //$mail->AddAddress("desired recipient no.2 optional");
                $mail->IsHTML(true);

                $mail->Subject  = $subject;
                $mail->Body     = $body;
                $mail->WordWrap = 50;

               If($mail->Send()){

                echo "<script type='text/javascript'>alert('Mail Send Successfully')</script>";
}
            } catch (phpmailerException $e) {
                echo "<script type='text/javascript'>alert('Failed')</script>";
                echo $e->errorMessage();
            }
        }
    ?>

我收到了这个错误。如何解决这个问题?

  

无法执行:/ var / qmail / bin / sendmail

1 个答案:

答案 0 :(得分:0)

你无法调用随机函数,并期望它可以神奇地工作。

您正在使用isSMTP()设置SMTP,但是当您的服务器看起来没有为它设置时,通过调用isSendmail()忽略所有这些。为什么这样?重新启用isSMTP并正确配置邮件服务器的脚本。

您还在禁用加密时请求身份验证;在任何现代服务器上都可能会失败。

您还使用旧版本的PHPMailer,并且您已将代码基于一个过时的示例。 Get the latest,并将您的代码基于the examples provided