如何检查电子邮件是否正在发送?

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

[我是从客户端获得服务器的,这是我第一次使用Amazon EC2服务器,我在服务器内部安装了Apache,MySQL和PHP,而客户端则安装了Amazon SES邮件服务器,它们向我发送了访问密钥和秘密-我的关键。对于电子邮件配置,我安装了composer,aws-sdk-php和PHPMailer,并在其中包含了密钥发送给我的代码。我尝试通过网站联系表发送电子邮件,但没有收到电子邮件。请在下面附上我的代码。请检查并告知我我的代码在哪里出错。

注意:我将插件安装在var / www / html文件夹中。

require '../vendor/autoload.php';

use Aws\Ses\SesClient;
use Aws\Exception\AwsException;

// Create an SesClient. Change the value of the region parameter if you're
// using an AWS Region other than US West (Oregon). Change the value of the
// profile parameter if you want to use a profile in your credentials file
// other than the default.
$SesClient = new SesClient([
    'profile' => 'default',
    'region'  => 'us-west-2',
    'key' => 'xxxxxxxx',
    'secret' => 'xxxxxxxxx'
]);

// Replace [email protected] with your "From" address.
// This address must be verified with Amazon SES.
$sender_email = '[email protected]';

// Replace these sample addresses with the addresses of your recipients. If
// your account is still in the sandbox, these addresses must be verified.
$recipient_emails = ['[email protected]','[email protected]'];

// Specify a configuration set. If you do not want to use a configuration
// set, comment the following variable, and the
// 'ConfigurationSetName' => $configuration_set argument below.
$configuration_set = 'ConfigSet';

$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was sent with Amazon SES using the AWS SDK for PHP.' ;
$html_body =  '<h1>AWS Amazon Simple Email Service Test Email</h1>'.
    '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'.
    'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'.
    'AWS SDK for PHP</a>.</p>';
$char_set = 'UTF-8';

try {
    $result = $SesClient->sendEmail([
        'Destination' => [
            'ToAddresses' => $recipient_emails,
        ],
        'ReplyToAddresses' => [$sender_email],
        'Source' => $sender_email,
        'Message' => [
            'Body' => [
                'Html' => [
                    'Charset' => $char_set,
                    'Data' => $html_body,
                ],
                'Text' => [
                    'Charset' => $char_set,
                    'Data' => $plaintext_body,
                ],
            ],
            'Subject' => [
                'Charset' => $char_set,
                'Data' => $subject,
            ],
        ],
        // If you aren't using a configuration set, comment or delete the
        // following line
        'ConfigurationSetName' => $configuration_set,
    ]);
    $messageId = $result['MessageId'];
    echo("Email sent! Message ID: $messageId"."\n");
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
    echo "\n";
}
php amazon-web-services amazon-ec2 amazon-ses
1个回答
1
投票
请检查以下内容:

1)使用AWS SES验证您的电子邮件地址。您必须验证您是否拥有电子邮件地址。

2)确认您的SMTP凭据,它们与您的AWS凭据

not相同。-在此页面上找到SMTP凭证(登录到AWS账户后):https://console.aws.amazon.com/ses/home?#smtp-settings

3)要确认PHP是否正常工作,请在EC2终端中运行php -v以确认您在屏幕上打印了PHP版本。

4)所有这些工作正常后,请确认您已正确安装PHPMailer(require './vendor/autoload.php';,将路径替换为系统上的路径)

5)如果您的AWS EC2实例位于美国西部以外的区域,请声明值并将其分配给$host$port值:

6)仍然无法正常工作?您从PHPMailer收到什么错误消息?请参见以下指南,了解有关PHPMailer的错误处理:Error handling with PHPMailer

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