[Emergency] use Zend_Mail to build the Mail Form. if smtp has a problem, I wrote a piece of code today and used Zend_Mail to build the Mail form. The program has never been running successfully, I suspect that there is a problem with my smtp configuration. in actual operation, $ smtp = newZend_Mail_Transport_Smtp (& qu [emergency] uses Zend_Mail to construct the mail delivery form. smtp has a problem.
Today, I wrote a piece of code and used Zend_Mail to construct the mail delivery form. The program is always unsuccessful. I suspect there is a problem with my smtp configuration.
$ Smtp = new Zend_Mail_Transport_Smtp ("smtp.gmail.com ",
Array (
'Port' => '25 ',
'Auth' => 'login ',
'Username' => 'xxxx @ gmail.com ',
'Password' => 'xxxxx'
));
Username and password all use real available mailboxes, and their brothers help to see where the problem is, 3Q
The overall code is as follows:
Email Delivery
Send email to Zend_Mail
Function encode ($ str ){
Return mb_convert_encoding ($ str, "gb2312", "auto ");
}
If ($ _ POST ['submit ']! = Null ){
Require_once 'zend/Mail. php ';
Require_once 'zend/Mail/Transport/Smtp. php ';
$ Smtp = new Zend_Mail_Transport_Smtp ("smtp.gmail.com ",
Array (
'Port' => '25 ',
'Auth' => 'login ',
'Username' => 'xxxx @ gmail.com ',
'Password' => 'xxxxx'
));
Zend_Mail: setDefaultTransport ($ smtp );
$ Mail = new Zend_Mail ();
$ Mail-> addTo ($ _ POST ['to']);
$ Mail-> setForm ("Circleinthehouse@gmail.com", encode ("Tian Jia "));
$ Mail-> setSubject (encode ($ _ POST ['subobject']);
$ Mail-> setBodyHtml (encode ($ _ POST ['body']);
$ Attach = $ mail-> createAttachment (file_get_contents ($ _ FILES ['fl '] ['tmp _ name']);
$ Attach-> type = $ _ FILES ['fl '] ['type'];
$ Attach-> filename = $ _ FILES ['fl '] ['name'];
$ Mail-> send ();
Print ("email sent successfully! ");
}
?>
------ Solution --------------------
SMTP Port error. The GMAIL port is not 25. refer to the official GMAIL instructions:
Other email client configurations
Standard description:
Enable POP in Gmail. Do not forget to click save changes after the operation is complete.
Configure your client to match the following settings:
Receiving mail (POP3) server-requires SSL: pop.gmail.com
Use SSL: Yes
Port 995
Send mail (SMTP) server-TLS or SSL: smtp.gmail.com (use authentication)
Use authentication: Yes
TLS/STARTTLS Port: 587
SSL port 465
Account name: your complete email address (including @ gmail.com or @ your_domain.com)
Email address: Your email address (username@gmail.com or username@your_domain.com)
Password: your Gmail password
------ Solution --------------------
Array (
'Port' => '25 ',
'Auth' => 'login ',
'Username' => 'xxxx @ gmail.com ',
'Password' => 'xxxxx'
));
To:
PHP code
array('port' => '587','auth' => 'login','username' => 'XXXX@gmail.com','password' => 'XXXXX'));