This link has been bookmarked by 56 people . It was first bookmarked on 14 Mar 2008, by spencech.
-
12 Dec 11
-
05 Oct 11
-
19 Apr 11
-
Note that to send email with PHP you need a working email server that you have permission to use: for Unix machines, this is often Sendmail; for Windows machines, you must set the SMTP directive in your php.ini file to point to your email server.
-
However, some mail clients cannot understand HTML emails. Therefore it is best to send any HTML email using a multipart construction, where one part contains a plain-text version of the email and the other part is HTML. If your customers have HTML email turned off, they will still get a nice email, even if they don't get all of the HTML markup.
-
$headers .= "\r Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
-
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit -
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit -
Content-type:multipart/alternative
-
Note that the content type of the message itself is sent as a mail header, while the content types of the individual parts of the message are embedded in the message itself.
-
boundary string
-
To send an email with attachment we need to use the multipart/mixed MIME type that specifies that mixed types will be included in the email.
-
$headers .= "\r Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
-
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
-
multipart/mixed
-
multipart/alternative
-
-
30 Mar 11
-
08 Feb 11
-
03 Jan 11
-
09 Dec 10
-
12 Oct 10
-
10 Oct 10
-
08 Sep 10
-
03 Aug 10
-
31 Jul 10
-
23 Jul 10
-
05 Jul 10
ed talmadge--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello Worl -
24 Jun 10
-
16 Jun 10
-
24 Feb 10
-
21 Sep 09
-
12 Sep 09
-
07 Sep 09
-
26 Jun 09
-
23 Feb 09
-
06 Oct 08
-
11 Sep 08
-
08 Jul 08
-
10 Jun 08
-
02 Jun 08
-
24 Apr 08
-
25 Mar 08
-
16 Mar 08
-
14 Mar 08
-
<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r
$headers = "From: webmaster@example.com\r Reply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
-
-
29 Jan 08
-
09 Jan 08
-
16 Dec 07
-
10 Sep 07
-
04 Sep 07
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.