如何使用Amazon SES在PHP中发送电子邮件

我将SES服务器安装到了我的Amazon ec2服务器中,并验证了电子邮件和SMTP。我想通过联系表单发送电子邮件,所以我得到了PHP代码表单亚马逊,我将PHPMailer安装在 var / www / html 文件夹中,并且将PHPMailer类称为不同的PHP文件。我在 validate文件夹中调用了不同的文件。我不明白我在哪里缺少代码详细信息我附加的图像请检查并告诉我我在哪里出错了,并帮助我解决这些问题。

<?php
      //Import the PHPMailer class into the global namespace
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    //SMTP needs accurate times,and the PHP time zone MUST be set
    //This should be done in your php.ini,but this is how to do it if you don't have access to that
    date_default_timezone_set('Etc/UTC');
    require '../vendor/autoload.php';
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //Enable SMTP debugging
    // SMTP::DEBUG_OFF = off (for production use)
    // SMTP::DEBUG_CLIENT = client messages
    // SMTP::DEBUG_SERVER = client and server messages
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;
    //Set the hostname of the mail server
    $mail->Host = 'email-smtp.us-east-1.amazonaws.com';
    //Set the SMTP port number - likely to be 25,465 or 587
    $mail->Port = 25;
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //username to use for SMTP authentication
    $mail->username = 'AKIA4I2MVSMJS34XXXX';
    //Password to use for SMTP authentication
    $mail->Password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
    //Set who the message is to be sent from
    $mail->setfrom('test@gmail.com','Jerad');
    //Set an alternative reply-to address
    $mail->addReplyTo('test123@hotmail.com','Arul');
    //Set who the message is to be sent to
    $mail->addAddress('welcome@gmail.com','John Doe');
    //Set the subject line
    $mail->Subject = 'PHPMailer SMTP test';
    //Read an HTML message body from an external file,convert referenced images to embedded,//convert HTML into a basic plain-text alternative body
    //$mail->msgHTML(file_get_contents('contents.html'),__DIR__);
    $mail->Body= 'testing Success';
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.png');
    //send the message,check for errors
    if (!$mail->send()) {
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message sent!';
    }
    ?>

点击发送按钮后,我收到此消息

如何使用Amazon SES在PHP中发送电子邮件

koto21cn 回答:如何使用Amazon SES在PHP中发送电子邮件

您正在将PHPMailerPHP PEAR Mailing Class混淆。您目前正在尝试同时使用两者。

尝试使用PHPMailer SMTP tutorial而不是PEAR类发送邮件。

,

我确实喜欢现在发送的电子邮件,但它将成为垃圾邮件

<?php
    //Import the PHPMailer class into the global namespace
                    require '../vendor/autoload.php';
            //Create a new PHPMailer instance
                    $mail = new PHPMailer;
            //Set who the message is to be sent from
                    $mail->setFrom($email,$name);
            //Set an alternative reply-to address

            //Set who the message is to be sent to
                    $mail->addAddress($toAdd,'TixRez');

            //Set the subject line
                    $mail->Subject = 'TixRez Client Registertion';
            //Read an HTML message body from an external file,convert referenced images to embedded,//convert HTML into a basic plain-text alternative body
            //$mail->msgHTML(file_get_contents('contents.html'),__DIR__);
                    $mail->Body = 'Full Name - '.$name. '<br><br> Phone Number - '.$phone. '<br><br> Email - '.$email. '<br><br> Company - '.$company. '<br><br> Address - '.$address. '<br><br> City - '.$city. '<br><br> Zip Code - '.$zipCode. '<br><br> Country - '.$country_name. '<br><br> Web Address - '.$webAddress. '<br><br> Company Size - '.$comSize;
            //Replace the plain text body with one created manually
                    $mail->AltBody = $message;
            //Attach an image file
            //$mail->addAttachment('images/phpmailer_mini.png');
            //send the message,check for errors
                    if (!$mail->send()) {
                        echo 'Mailer Error: '. $mail->ErrorInfo;
                    } else {
                        echo 'Message sent!';
                    }

    ?>
本文链接:https://www.f2er.com/2831865.html

大家都在问