PHP mail function to send HTML format mail

Source: Internet
Author: User
Tags format message html tags ini md5 phpinfo word wrap

The Mail function under Windows system needs to be configured

1. Download from http://glob.com.au/sendmail/Sendmail.zip
2. Extract to C: Under, such as C:\php\sendmail, the best short path, long path name may cause problems.
3. Modify PHP.ini as follows
Sendmail_path = "C:\wamp\sendmail\sendmail.exe-t"
4. Modify the Sendmail.ini according to your own configuration environment.
It is a good idea to enable debug.log_file,error_logfile for the first time to see if SendMail is active.

Configuring the Install Mail function on a Linux system

Yum-y Install SendMail

Installation Successful

/etc/rc.d/init.d/sendmail start

Mail-s "abc" 165482921@qq.com < phpinfo.php

Tips

-bash:mail:command not found

So, how do I get this mail order out of here?

Yum-y Install MAILX

It's all set up.

Mail-s "abc" 165482921@qq.com < phpinfo.php

A look at the mailbox, there, Oh, the original two orders can do so AH

First look at a code example

  code is as follows copy code

$to = ' xxxxx@gmail.com ';
$from = ' Solagirl <sola@solagirl.net> ';
$subject = ' Mail subject ';
$message = ' HTML content (with HTML tags) ';
Defines the boundary, the boundary value as uniquely as possible
$semi _rand = MD5 (time ());
$mime _boundary = "==multipart_boundary_x{$semi _rand}x";
The header declaration for a multi-part message differs from a single format
$headers. = "mime-version:1.0\n". "Content-type:multipart/alternative; Boundary=\ "{$mime _boundary}\" ";
$headers. = "From: $from \ n";
Multi-part message-HTML version
$mailbody = "--{$mime _boundary}\n". "Content-type:text/html; Charset=\ "Utf-8\".
"Content-transfer-encoding:7bit\n\n". $message. "\ n";
Multi-Part Message-Plain text version
$mailbody. = "--{$mime _boundary}\n". "Content-type:text/plain; Charset=\ "Utf-8\".
"Content-transfer-encoding:7bit\n\n". Strip_tags ($message). "\ n";
Multi-part message end
$mailbody. = "--{$mime _boundary}--";
Mail ($to, $subject, $message, $headers);

From the example above, to use a multiple-part message to send an e-mail message, the header is different from sending a single format message, you need to declare that the content sent is multipart and define boundaries (boundary)

The code is as follows Copy Code
content-type:multipart/alternative; Boundary= ' {$mime _boundary} '

This tells the e-mail client that additional Content-type information should be found in the message, which contains the boundary information. The boundary separates the message into parts, starting with two dashes (–) and at the beginning of the message, between the parts, and at the end of the message. The content of this boundary is not important, the key is to make it as unique as possible, so it cannot be a duplicate value in the message, so you can use any combination of symbols, numbers, and letters, and it doesn't matter how many people choose to use the rand () or MD5 () hash. How you use it is entirely up to the design staff. [2]

If you use Phpmailer to send a message, you need simple code to implement a partial message, look at the following code snippet [3]

The code is as follows Copy Code

$mail->body = $body;
$mail->altbody Store Plain text versions
$mail->altbody = Strip_tags ($body);
$mail->wordwrap = 50; Set word Wrap
$mail->ishtml (TRUE);
$mail->msghtml ($body);
$mail->send ();


if Warning:mail () [Function.mail]: SMTP server response:530 5.7.0 must issue a STARTTLS command I this message is not configured well, we read the article The start configuration method.

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.