我可能有完全错误,但是当我尝试运行此代码时,我想将模板电子邮件发送给用户,这项工作在我的本地服务器上完美,但现在已经上传到我的网站,它只是发送一个空白电邮。如果这个代码顺便说一句,我就把我的密码和电子邮件发给我了。
<?php
function format_email($info, $format){
//set the root
$root = $_SERVER['DOCUMENT_ROOT'].'dolearnfinance.com/email_templates';
//grab the template content
$template = file_get_contents($root.'/signup_template.'.$format);
//replace all the tags
$template = preg_replace('({FNAME})', $info['fname'], $template);
$template = preg_replace('({EMAIL})', $info['email'], $template);
$template = preg_replace('({KEY})', $info['key'], $template);
$template = preg_replace('({SITEPATH})','http://www.dolearnfinance.com', $template);
//return the html of the template
return $template;
}
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
$email = $info['email'];
//setup the mailer
// Create the Transport
$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('*')
->setPassword('*')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transporter);
// Create a message
$message = Swift_Message::newInstance('Verifi Email')
->setSubject('Welcome to doLearnFinnace')
->setFrom(array('noreply@doLearnFinnace.com' => 'doLearnFinnace'))
->setTo(array($email))
->setBody($body_plain_txt)
;
// Send the message
$result = $mailer->send($message);
return $result;
}
?>