Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

php - Cakephp SMTP emails syntax error

I've got a problem with email sending in cake. My method looks like this:

$this->Email->smtpOptions = array(
            'port'=>'465', 
            'timeout'=>'30',
            'auth' => true,
            'host' => 'ssl://smtp.gmail.com',
            'username'=>'[email protected]',
            'password'=>'mypass',
        );

        $this->Email->from    = "admin@localhost";
        $this->Email->to      = "[email protected]";
        $this->Email->subject = "Test";
        $this->Email->sendAs = "text";

        $this->Email->delivery = 'smtp';

        $this->Email->send('Hello message body!');

But when I try to send the email I get:

555 5.5.2 Syntax error. l3sm512374fan.0

What do I need to chnage in order for this to work?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Per RFC2821, to which Google's SMTP servers seem to be a stickler on, the format of the email addresses should be in the following way:

Recipient Name <[email protected]>
-or-
<[email protected]>

Do this for both the from and to address, and you should be good to go. If you don't have the name of the user, then you can just repeat the email:

$this->Email->to = "[email protected] <[email protected]>";
-or-
$this->Email->to = "<[email protected]>";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...