我有一个php应用程序,目前使用php mail()发送电子邮件。我想使用smtp(最好是sendgrid)发送邮件作为共享服务器有限制/小时。
我的代码如下:
admin_sendmail.php
class sendmail
{
public static function sendAccountActivateMail($to,$activate_code,$user_id,$user_name,$user_pwd)
{
$flg = false;
try
{
$subject = 'Mysite Account Activation';
$message = "Welcome to Mysite! n";
$message .= "Please activate your account by clicking the link below n";
$message .= "http://myzone.mysite.com/account_activation.php?command=activate&surebuzz_code=$user_id&activation_code=$activate_code n";
$message .= "Username: $user_name n";
$message .= "Password: $user_pwd n";
$email = "info@mysite.com";
$headers = "From: $emailrnReply-To: $email";
$flg = mail($to,$subject,$message,$headers);
}
catch(Exception $e)
{
$flg = false;
}
return $flg;
}
}
谁能帮助转换这使用SMTP与phpmailer/swiftmailer或sendgrid?我对php很陌生。这是另一个我失去联系的人写的。
谢谢
我就是这么用的
require_once ('class.phpmailer.php');
class myPHPMailer extends PHPMailer {
public function __construct(){
$this->IsSMTP();
$this->SMTPAuth = true;
$this->SMTPSecure = "tls"; //Or SSL?
$this->Host = "smtp.gmail.com";
$this->Port = 587; //Maybe 465 instead? SSL only?
//$this->Port = 25;
$this->Username = "xxx";
$this->Password = "xxx";
}
$mail = new myPHPMailer();
$mail->AddReplyTo("xxx@xxx.com","xxx");
$mail->From = "xxx@xxx.com.com";
$mail->FromName = "xxx";
$mail->Subject = "What ever";
$mail->WordWrap = 50; // set word wrap
$mail->Body = $msg;
$mail->AddAddress("xxx@gmail.com", "xxx");
$mail->Send();