如何使用 Amazon SES 在 PHP 中发送电子邮件
How to send the email in PHP using Amazon SES
我将 SES 服务器安装到我的亚马逊 ec2 服务器中,并验证了电子邮件和 SMTP。我想通过我的联系表发送电子邮件,所以我得到了亚马逊的 PHP 代码我在 var/www/html 文件夹中安装了 PHPMailer 并且我调用 PHPMailer class 不同的 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!';
}
?>
点击发送按钮后我收到了这条消息
你在混淆 PHPMailer with PHP PEAR Mailing Class。您目前正在尝试同时使用两者。
尝试使用 PHPMailer SMTP tutorial 代替 PEAR class 发送邮件。
我很喜欢这封电子邮件,但它会变成垃圾邮件
<?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!';
}
?>
我将 SES 服务器安装到我的亚马逊 ec2 服务器中,并验证了电子邮件和 SMTP。我想通过我的联系表发送电子邮件,所以我得到了亚马逊的 PHP 代码我在 var/www/html 文件夹中安装了 PHPMailer 并且我调用 PHPMailer class 不同的 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!';
}
?>
点击发送按钮后我收到了这条消息
你在混淆 PHPMailer with PHP PEAR Mailing Class。您目前正在尝试同时使用两者。
尝试使用 PHPMailer SMTP tutorial 代替 PEAR class 发送邮件。
我很喜欢这封电子邮件,但它会变成垃圾邮件
<?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!';
}
?>