Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email php中的邮件配置错误_Email_Phpmailer - Fatal编程技术网

Email php中的邮件配置错误

Email php中的邮件配置错误,email,phpmailer,Email,Phpmailer,我设计了我的网站,托管在我的亚马逊ec2实例上,我在godaddy(www.mydomain.com)上购买了我的域名。现在我想在网站的联系人表单页面中配置邮件。。下面是我的代码,我不知道我哪里弄错了代码 <?php if(isset($_REQUEST['submit'])) { try { $name = $_POST['name']; echo "<script ty

我设计了我的网站,托管在我的亚马逊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();
            }
        }
    ?>

你不能调用随机函数,期望它能神奇地工作

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

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


您还使用了旧版本的PHPMailer,并且您的代码基于一个过时的示例,并以您的代码为基础。

这是无关紧要的——您正试图使用的代码才是最重要的。