0

我有一个 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: $email\r\nReply-To: $email";
            $flg = mail($to,$subject,$message,$headers);
        }
        catch(Exception $e)
        {
            $flg = false;
        }
        return $flg;
    }

}

谁能帮助将其转换为通过 phpmailer/swiftmailer 或 sendgrid 使用 SMTP?我对php很陌生。这是由我失去联系的其他人编码的。

谢谢

4

1 回答 1

1

这就是我使用的。

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();
于 2013-03-16T14:08:32.323 回答