使用php的amazon托管中的邮件配置错误?

时间:2018-05-02 05:45:49

标签: php email

我设计了我的网站并托管在我的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 = <<<EOD

    <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>

    EOD;



     $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;
    $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)

试一试。这可能有帮助。您必须使用不同的电子邮件来自邮件。 而不是使用

$mail->From = "support@mydomain.com"

您必须在此处使用其他电子邮件:

$mail->From = "supportexample@mydomain.com";

require_once('phpmailer/class.phpmailer.php');
require_once('phpmailer/class.smtp.php');                                                               

$mail = new PHPMailer; 
$mail->isSMTP();
$mail->Host = "email-smtp.us-east-1.amazonaws.com"; // SMTP HOST
$mail->SMTPAuth = true;
$mail->Username = "support@mydomain.com"; // SMTP username
$mail->Password = "********"; // SMTP password
$mail->SMTPSecure = "ssl"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = "465"; // TCP port to connect to 587
$mail->From = "supportexample@mydomain.com";
$mail->FromName = "Domain Example";
$mail->addAddress("XXXX@gmail.com");
$mail->addReplyTo("supportexample@mydomain.com");
$mail->isHTML(true);
$mail->Subject = "Hello Test";
$mail->Body    = "Test Message Working With Us";
if($mail->send()){
    return true;
}
else{
    return $mail->ErrorInfo;    
}