"First Aid" use Zend_mail to build mail Messenger forms with SMTP issues

Source: Internet
Author: User
Tags gmail password
"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 ');
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.