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

问题描述 投票:0回答:1

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

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require '../vendor/autoload.php';
// Replace [email protected] with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', '[email protected]');

// Replace [email protected] with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', '[email protected]');

// Replace smtp_username with your Amazon SES SMTP user name.
define('USERNAME','XXXXXXXXXXXXX');

// Replace smtp_password with your Amazon SES SMTP password.
define('PASSWORD','XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');

// If you're using Amazon SES in a region other than US West (Oregon),
// replace email-smtp.us-west-2.amazonaws.com with the Amazon SES SMTP
// endpoint in the appropriate region.
define('HOST', 'email-smtp.us-east-1.amazonaws.com');

// The port you will connect to on the Amazon SES SMTP endpoint.
define('PORT', '587');

// Other message information
define('SUBJECT','Hello from Driffle!');
define('BODY','Test Email');

$headers = array (
    'Content-Type' => "text/html; charset=UTF-8",
    'From' => SENDER,
    'To' => RECIPIENT,
    'Subject' => SUBJECT
);

$smtpParams = array (
    'host' => HOST,
    'port' => PORT,
    'auth' => true,
    'username' => USERNAME,
    'password' => PASSWORD
);

**alert();
Until here alert is working**


// Create an SMTP client.
$mail = Mail::factory('smtp', $smtpParams);

 **alert();
 after here alert not working**

// Send the email.
$result = $mail->send(RECIPIENT, $headers, BODY);

if ($result!="") {
    echo("Email not sent. " .$result->getMessage() ."\n");
} else {
    echo("Email sent!"."\n");
}
php amazon-web-services email amazon-ses
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.