Question:
How do i send html emails in php?
anonymous
2010-03-19 13:08:46 UTC
Hi I've been using this php script to send emails from my browser:

"
$to = "email@to.send";
$subject = "Subject";
$message = "Message";
$from = "blaa@blaa.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> "

But now i want to send more complex html emails with images tabels...
I want to be able to just create a html code in a html editor paste it to the php script and send the email (i don't know if thats possible).

Can someone help me figure how to send complex html email with a php scrip? Thanks in advance!
Three answers:
anonymous
2010-03-20 00:05:06 UTC
Use a server-side script language if your web site allows it. Otherwise, you will have to use a client-side dependent "mailto:" action to get the form info sent to you.



Your current hosting package MUST allow SMTP ( http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol ) to work. Otherwise, no email can be sent.



Use any of the below sites to make the workable form you need:



For making forms:



These are really good online form makers. Just follow the instructions for making it and uploading file(s).



http://www.phpform.org/

http://www.tele-pro.co.uk/scripts/contact_form/

http://www.jotform.com/?gclid=CNKhqei1wJ4CFRQhnAod6laUqA (WYSIWYG Form Maker)

http://www.thesitewizard.com/wizards/feedbackform.shtml

http://www.thepcmanwebsite.com/form_mail.shtml



http://emailmeform.com/

http://www.freecontactform.com/

http://www.reconn.us/content/view/12/34/ (Download - Contact Us Script)

http://formsmarts.com/
Dean.
2010-03-19 20:15:15 UTC
You need to send proper html headers that say the message in wrote in html. This following code is a basic example of what i use




//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\n

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

//add boundary string and mime type specification

$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";

//define the body of the message.

ob_start(); //Turn on output buffering

?>

--PHP-alt-

Content-Type: text/plain; charset="iso-8859-1"

Content-Transfer-Encoding: 7bit



Hello World!!!

This is simple text email message.



--PHP-alt-

Content-Type: text/html; charset="iso-8859-1"

Content-Transfer-Encoding: 7bit



Hello World!



This is something with HTML formatting.





--PHP-alt---


//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";

?>





















===========================================

This is able to send a html message but if the recipient of the email doesnt accept html or html is turned off the plain text version is send. Id advise using this code with $_POST or $_Get commands so you dont need to keep working with the code.
?
2010-03-19 20:32:59 UTC
i have a script that you could use.... that will send data that you put in a form you can see here on www.eatmarketing.co.uk or here is a tutorial to get you started



http://www.freewebmasterhelp.com/tutorials/php/6



if you require further help get in contact with me here http://www.crossloop.com/antworks


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...