簡體   English   中英

如何使用 Amazon SES 在 PHP 中發送電子郵件

[英]How to send the email in PHP using Amazon SES

我將 SES 服務器安裝到我的亞馬遜 ec2 服務器中,並驗證了電子郵件和 SMTP。 我想通過我的聯系表格發送電子郵件,所以我得到了亞馬遜的 PHP 代碼表格我在var/www/html文件夾中安裝了 PHPMailer,我將 PHPMailer 類稱為不同的 PHP 文件。 我調用了驗證文件夾中的不同文件。 我不明白我在哪里遺漏了我附加的代碼細節圖片請檢查並讓我知道我在哪里犯了錯誤並幫助我解決這些問題。

<?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!';
    }
    ?>

單擊發送按鈕后,我收到此消息

在此處輸入圖片說明

您將PHPMailerPHP PEAR Mailing Class混淆了。 您目前正在嘗試同時使用兩者。

嘗試使用PHPMailer SMTP 教程來發送郵件而不是 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!';
                    }

    ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM