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