-1

我对设置 Sparkpost SMTP 有点困惑。例如,我需要从我的网站向客户发送自动电子邮件。注册时的欢迎信息,咨询提醒电子邮件等。网站将自动生成电子邮件。

他们在 Sparkpost 上显示:

define('PHPMAILERHOST', 'smtp.sparkpostmail.com');
$phpmailer_smtpuser = 'SMTP_Injection';
$phpmailer_smtppassword = '<API_KEY>';
define('PHPMAILERPORT', 587);

但是,当我搜索有关 Stackoverflow 的更多信息时,我发现了这一点:

$config['mailtype'] = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sparkpostmail.com';
$config['smtp_user'] = 'user';
$config['smtp_pass'] = 'password';
$config['smtp_crypto'] = 'tls';
$config['smtp_port'] = '587';
$condig['crlf'] = "\r\n";
$config['newline'] = "\r\n";

鉴于上述情况,将进行以下工作:

//Sparkpost configuration
$config['mailtype'] = "html";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sparkpostmail.com';
$config['smtp_user'] = 'user';
$config['smtp_pass'] = 'password';
$config['smtp_crypto'] = 'tls';
$config['smtp_port'] = '587';
$condig['crlf'] = "\r\n";
$config['newline'] = "\r\n";

//My email code
$to_email = "$Email";
$from_email = "me@mydomain";
$subject = "Email Subject";
$comment =  "<html>Email message</html>";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= "From: Info <" . $from_email . ">\r\n";
//send email
mail($to_email, "$subject", $comment, $headers);

我问的原因是,我不想设置、测试和电子邮件通过,虽然我的印象是我的 Sparkpost 设置正在工作,但电子邮件通过我的主机。

4

1 回答 1

1

如果您想使用 SparkPost,您可以使用他们的库,或者按照 Jon Stirling 的建议,将 PHPMailer 与 SparkPost 配置一起使用。

使用 SparkPost PHP 库

使用 PHPMailer

  • 在脚本中包含 phpMailer 类

  • 将其配置为使用 SparkPost,如下所示

$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.sparkpostmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'SMTP_Injection';
$mail->Password = '<API_KEY>'; //make sure you add SMTP permission to API Key
$mail->setFrom('testing@sparkpostbox.com'); //you can use w/o adding your sending domain like ~50 messages. Once you add your sending domain, use that. 
$mail->addAddress('recipient@domain.com');
$mail->Subject = 'Test subject';
$mail->Body    = 'Hello World!';
$mail->send();
于 2019-02-18T15:12:56.310 回答