【问题标题】:How do I setup Sparkpost smtp如何设置 Sparkpost smtp
【发布时间】:2019-02-18 10:12:18
【问题描述】:

我对设置 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 设置正在工作,但电子邮件通过我的主机。

【问题讨论】:

  • 随机数组不会自动成为发送电子邮件的设置。就目前而言,电子邮件似乎只是通过默认系统 MTA 而不是通过 SparkPost 发送的。
  • @JonStirling。谢谢。您能帮助我了解如何使用 Sparkpost SMTP 的正确方法吗?
  • 我的建议是使用 PHPMailer 之类的库,并按照使用说明进行操作,并提供连接到 SparkPost 的详细信息。快速的谷歌搜索应该可以为您提供所需的一切。

标签: php email sparkpost


【解决方案1】:

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

使用 SparkPost PHP 库

使用 PHPMailer

  • 在脚本中包含 phpMailer 类

  • 将其配置为使用 SparkPost,如 below

$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();

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 2023-04-01
    • 1970-01-01
    • 2019-05-26
    • 2019-01-09
    • 1970-01-01
    • 2014-08-28
    • 2021-03-07
    • 2013-10-14
    相关资源
    最近更新 更多