I am a beginner in php, mail (), and want to consult

Source: Internet
Author: User
For questions about sending emails via php and mail (), I would like to ask if I am studying the basic syntax in w3school and see the case of sending emails.

$ To = "someone@example.com ";
$ Subject = "Test mail ";
$ Message = "Hello! This is a simple email message .";
$ From = "someonelse@example.com ";
$ Headers = "From: $ from ";
Mail ($ to, $ subject, $ message, $ headers );
Echo "Mail Sent .";

?>
Test failed to send email
I would like to ask if php mail can be implemented with just a few simple codes? Do you not need the sender's account password or other settings?


Reply to discussion (solution)

Use php mailer to mail please refer to video tutorial http://pan.baidu.com/s/1rIJeU or http://www.zixue.it/portal.php? Mod = list & catid = 11

The mail function can only send emails using a sender server that does not require user authentication.
If you use a sender server that does not require user authentication, you must configure it in php. ini to use the mail function.

Require_once ('email. class. php ');
//###################################### ####

$ Smtpserver = "smtp.163.com"; // SMTP server
$ Smtpserverport = 25; // SMTP server port
$ Smtpusermail = "your @ 163.com"; // SMTP server user email
$ Smtpemailto = $ email; // to whom the email is sent
$ Smtpuser = "name"; // User account of the SMTP server
$ Smtppass = "addfgtpd"; // user password of the SMTP server

$ Mailsubject = "subject"; // subject
$ Mailbody = "Mail content" // mail content
$ Mailtype = "HTML"; // The email format (HTML/TXT). TXT is a text email.
$ Smtp = new smtp ($ smtpserver, $ smtpserverport, true, $ smtpuser, $ smtppass); // Here, true indicates that authentication is used; otherwise, authentication is not used.
$ Smtp-> debug = FALSE; // whether to display the sent debugging information
$ Smtp-> sendmail ($ smtpemailto, $ smtpusermail, $ mailsubject, $ mailbody, $ mailtype );
?>

If you need to authenticate, use phpmailer. you can simply configure it a few times.

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.