Mail () in PHP is always unsuccessful. How can this problem be solved?

Source: Internet
Author: User
Mail () in PHP is always unsuccessful. & Lt ;? Php $ to & nbsp; = & nbsp; "757006080@qq.com"; $ subject & nbsp; = & nbsp; "Test & nbsp; mail"; $ message & nbsp; = & nbsp; "He PHP always fails to send emails via mail.
 
$to = "757006080@qq.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "757006080@qq.com";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else 
echo "Sorry,mail sent failed!"

?>


Wamp used in the development environment, download and install the sendmail program, and change php. ini and sendmail. ini according to the Internet.
Foxmail 7.1 is used to create an account for your QQ mailbox and the POP3/SMTP service is enabled. Change the sending server to POP3 and use the same authentication as the receiving server. The result still reports the following Error: Warning: mail (): SMTP server response: 503 Error: need EHLO and AUTH first! In F: \ PHP \ wamp \ www \ mail. php on line 8
I don't know where it is wrong. please kindly advise. Thank you !!!
Mail () sendmail QQ mail shared:
------ Solution --------------------
You can try phpmailer.


$ Path = realpath (dirname (_ FILE _). '/../libraries/Mail. php ';
Include ("$ path ");;

$ Mail = new Mail (); // create a new object
$ Mail-> IsSMTP (); // you can specify the SMTP mode to send messages.
$ Mail-> SMTPAuth = true; // you need a license to set SMTP.
$ Mail-> SMTPSecure = "ssl"; // The SMTP host of Gmail needs to use SSL secure authentication
$ Mail-> Host = "smtp.gmail.com"; // SMTP Host of Gamil
$ Mail-> Port = 465; // The SMTP Port of the SMTP master machine of Gamil is Port 465.
$ Mail-> CharSet = "UTF-8"; // you can specify a portable component.

$ Mail-> Username = "onlyfortestlzz@gmail.com"; // Set your certificate
$ Mail-> Password = "abcde"; // you can specify the secret of your certificate.

$ Mail-> From = "onlyfortestlzz@gmail.com"; // Set the sender's mailbox
$ Mail-> FromName = "staff member"; // Set the sender's name

$ Mail-> Subject = "PHPMailer Courier letter"; // Set the Subject matter
$ Mail-> Body = "Hello ";
// Set the content of the firmware.
$ Mail-> IsHTML (true); // set the content of the email to HTML.
$ Mail-> AddAddress ($ this-> input-> post ('backemail'), $ value-> username); // specify the receiver and its name.

If (! $ Mail-> Send ()){
Echo 'OK ';
}

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.