我正在尝试使用SES和PHP SDK v3发送电子邮件。但它证明相当困难。就我而言:
require_once '/src/aws/aws-autoloader.php';
$ses = new Aws\Ses\SesClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'mykeyhere',
'secret' => 'mysecrethere',
],
]);
我尝试过复制各种指南中的代码,但似乎都没有。有人可以告诉我如何用php发送电子邮件吗?
答案 0 :(得分:3)
首先设置您的SES:
using (var streamReader = new StreamReader(path))
{
using (var memoryStream = new MemoryStream())
{
streamReader.BaseStream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}
发送电子邮件:
$ses = Aws\Ses\SesClient::factory([
'key' => 'AWS_KEY',
'secret' => 'AWS_SECRET_KEY',
'region' => 'us-east-1'
]);
很少有注意事项
答案 1 :(得分:0)
我知道你问过如何在SES API中使用,但我使用PHPMailer来完成这项任务。结果会一样。
<?php
require (dirname(__FILE__) . '/phpmailer/PHPMailerAutoload.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];
// send email
$mail = new PHPMailer();
$mail->isSMTP();
$mail->isHTML(false);
$mail->Host = 'email-smtp.us-west-2.amazonaws.com'; // Or put your zone here
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = 'mykeyhere';
$mail->Password = 'mysecrethere';
$mail->setFrom('<email added in ses>', "$name");
$mail->addAddress('<destination email>');
$mail->Subject = "design2co.de";
$mail->Body = "Nome: $name \n" .
"Email: $email \n" .
"Mensagem: $msg \n";
if(!$mail->send()) {
echo json_encode(array("status" => 404));
} else {
echo json_encode(array("status" => 200));
exit;
}
}
?>