Php Mail Function

Hi

How do i send HTML form data using php mail function.

I managed to use mail function to send email for a message, but I would like to send more than just a message. I have a html form which calls a php script to send email.

The form has couple of input type text and radio fields. Please see here:

http://www.hostcheese.com/FreeAffiliateWebsite/submitdetails/submitdetailstest.html

My current php script that send message only is below:

[php]<?php
$email_address = $_POST[‘email’] ;
$subject = $_POST[‘subject’] ;
$message = $_POST[‘message’] ;
mail( "[email protected]", “Subject: $subject”,
$message, “From: $email” );
echo “Thank you for using our mail form.
”;
echo “Your email has been sent.”;
?>

[/php]

How do I update this php script to send the form data on the above link.

Thanks

Hi use below code for send HTML content in mail [php] //save this file as testmail.php and run $to = "[email protected]"; // receiver email, replace this mail id from your for testing $from = "[email protected]"; //sender email $subject = "Hello! This is HTML email"; // contain your subject line for email //$message contain your html code you can modify it as per your requirement. I am putting static HTML code $message = <<<EOF Looool!!! I am reciving HTML email......
Thanks Sanjay!
* sr.com

*** Now you Can send HTML Email
Regards
SR EOF;

// define your headers here.
$headers = “From: $from\r\n”;
/* // your must define below line for send HTML content in mail. if you forget or not use than you can not sent HTML content in mail. It define Content type of mail.*/
$headers .= “Content-type: text/html\r\n”;
mail($to, $subject, $message, $headers);
[/php]

i hope this will help for you…
reply your feedback
~SR~

Thanks SR.
I am not sure how your code will work in my case.
I have a separate HTML and php script. HTML calls php script to send email.

Let me paste my html below:

[code]

Email:

Subject:

Clickbank ID:

Location:

Domain Name:

Select Your Website:

Acne Free in 3 Days
Dog Training Secrets
Earth 4 Energy
Fat Loss 4 Idiots
Gold Swing Guru

My Air Fare Secrets

Truth About Abs


[/code]

Now I need to modify my php script (please see my first post) to get all the form data (cbid, location, domain, etc) and finally to sent to an email address specified in the php.

Thanks
Naz

OK, please replace your php script code with below code [php] //change this to your email. $to = "[email protected]"; $from = $_POST['email']; $subject = $_POST['subject'];
//begin of HTML message
$message = '<html>
				  <body bgcolor="#DCEEFC">
					<center>
						<b>I am reciving HTML email......</b> <br>
						<font color="red">Contact Form detail Fillup by User </font> <br>
						<table width="100%" border="1">
						  <tr><td>Sender Email</td><td>'.$_POST['email'].'</td></tr>
						  <tr><td>Clickbank ID</td><td>'.$_POST['cbid'].'</td></tr>
						  <tr><td>Location</td><td>'.$_POST['location'].'</td></tr>
						  <tr><td>Domain Name</td><td>'.$_POST['domain'].'</td></tr>
						  <tr><td>Website</td><td>'.$_POST['website'].'</td></tr>
						</table>
						<font color="red">Thanks Sanjay!</font> <br>
					</center>
				  </body>
				</html>';

//end of message
$headers = “From: $from\r\n”;
$headers .= “Content-type: text/html\r\n”;

// now lets send the email.
mail($to, $subject, $message, $headers);

echo “Thank you for using our mail form.
”;
echo “Your email has been sent.”;
[/php]

Note: you can modify $message structure as per your requirement, i have used simple table structure.

I hope now your problem is resolve…
reply your feedback.
~SR

thanks sanjay, with minor changes to your code - i finally got the email :slight_smile:

i got the email in html tags like this:

[code]

I am reciving HTML email......
Contact Form detail Fillup by User
Full Name hkjh
Sender Email kjhkjh
Clickbank ID kjhkjh
Location kjhkjh
Domain Name kjhkjh
Website
Thanks Sanjay!
[/code]

how can hange the code to avoide html tags in the email and only get user data:

here is new mailformphp:
[php]<?php

$from = $_POST[‘email’];
$subject = $_POST[‘subject’] ;
$message = $_POST[‘message’] ;
$message = ’

I am reciving HTML email......
Contact Form detail Fillup by User
Full Name '.$_POST['yourname'].'
Sender Email '.$_POST['email'].'
Clickbank ID '.$_POST['cbid'].'
Location '.$_POST['location'].'
Domain Name '.$_POST['domain'].'
Website '.$_POST['website'].'
Thanks Sanjay!
'; //end of message

// now lets send the email.

mail( "[email protected]", “Subject: $subject”,
$message, “From: $email” );
echo “Thank you for using our mail form.
”;
echo “Your email has been sent.”;
?>[/php]

thanks

Also I realised that the code is not sending radio data of website in the email.
the selected website is missing in the email

HI Sanjay

I managed to fix the radio issue with tag

see the code below:
[php]

[/php]

and in html

[code]

Select Your Website:


Acne Free in 3 Days Dog Training Secrets Earth 4 Energy Fat Loss 4 Idiots Gold Swing Guru My Air Fare Secrets Truth About Abs [/code]

now i just need to remove the html tags in the received email

thanks

Full Name '.$_POST['yourname'].'
Sender Email '.$_POST['email'].'
Clickbank ID '.$_POST['cbid'].'
Location '.$_POST['location'].'
Domain Name '.$_POST['domain'].'
Website '.$_POST['website'].'

Great

Html tags have been removed in the mail received

here is the code:
[php]$message = ’
Full Name: ‘.$_POST[‘yourname’].’
Sender Email: ‘.$_POST[‘email’].’
Clickbank ID: ‘.$_POST[‘cbid’].’
Location: ‘.$_POST[‘location’].’
Domain Name: ‘.$_POST[‘domain’].’
Website: ‘.$_POST[‘website’].’
';[/php]

I would like to thanks Sanjay for his help :slight_smile:

Thanks nazjones, it's nice to see that finally your problem is resolve. :) :)
Sponsor our Newsletter | Privacy Policy | Terms of Service