"First Aid" using Zend_mail to build mail Messenger forms, SMTP has a problem
Writing a piece of code today, using Zend_mail to build a mail Messenger form, the program always runs unsuccessfully, I suspect that there is a problem with my SMTP configuration, the actual runtime
$SMTP = new Zend_mail_transport_smtp ("smtp.gmail.com",
Array
' Port ' = ' 25 ',
' Auth ' = ' login ',
' Username ' = [email protected] ',
' Password ' = ' XXXXX '
));
Username,password all use the real available mailbox, their brothers help to see where the problem, 3Q
The overall code is as follows:
<title>Mail Messenger</title>
Mail Messenger 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 ' = [email protected] ',
' Password ' = ' XXXXX '
));
Zend_mail::setdefaulttransport ($SMTP);
$mail = new Zend_mail ();
$mail->addto ($_post[' to ');
$mail->setform ("[Email protected]", Encode ("Tian"));
$mail->setsubject (Encode ($_post[' subject '));
$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 ("Mail sent successfully!") ");
}
?>
------Solution--------------------
SMTP port error, Gmail's port is not 25, refer to the official Gmail Note:
Configuring additional mail client Descriptions
Standard Description:
Enable POP in Gmail. Do not forget to click Save changes when the operation is complete.
Configure your client to match the following settings:
Incoming mail (POP3) server-Requires SSL:pop.gmail.com
Using SSL: Yes
Port: 995
Outgoing mail (SMTP) server-requires TLS or SSL:smtp.gmail.com (authentication is used)
Use authentication: Yes
TLS/STARTTLS Port: 587
Port for SSL: 465
Account Name: Your full e-mail address (including @gmail. com or @your_domain. com)
Email Address: Your email address ([email protected] or [email protected]_domain.com)
Password: your Gmail password
------Solution--------------------
Array
' Port ' = ' 25 ',
' Auth ' = ' login ',
' Username ' = [email protected] ',
' Password ' = ' XXXXX '
));
Modified to:
PHP Code
Array (' port ' = ' 587 ', ' auth ' = ' login ', ' username ' = [email protected] ', ' password ' = ' XXXXX ');