How to send image in PHP mail function - php

I want to send image in mail.How to add image so that it will show in the email
I want to add image to the CLIENT MESSAGE BODY.
How to use html in client message body?
Here is my code :
<?php
/* subject and email varialbles*/
$emailSbuject = 'Enquiry';
$webMaster = 'vivek#a.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/
$nameFeild = $_POST['name'];
$cityFeild = $_POST['city'];
$countryFeild = $_POST['country'];
$emailFeild = $_POST['email'];
$phoneFeild = $_POST['phone'];
$otherFeild = $_POST['other'];
$questionFeild = $_POST['question'];
$commentFeild = $_POST['comment'];
$phone1Feild = $_POST['phone1'];
$hear1Feild = $_POST['hear1'];
$hear2Feild = $_POST['hear2'];
$hear3Feild = $_POST['hear3'];
$hear4Feild = $_POST['hear4'];
$referralFeild = $_POST['referral'];
$otherhearFeild = $_POST['otherhear'];
// admin message body
$body= <<<EOD
Contact Form Details of $nameFeild
Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n
Email: $emailFeild \n
Contact Phone: $phoneFeild \n
Other Phone: $otherFeild \n
Question: $questionFeild \n
Comment: $commentFeild \n
Contact Over: $phone1Feild \n
Known Us through: \n
$hear1Feild
$hear2Feild
$hear3Feild
$hear4Feild
$referralFeild
$otherhearFeild
EOD;
// Client message body
$body2 = <<<EOD
Dear $nameFeild
Thank u for contacting IntaxFin. One of our representatives will contact you the soonest. If you have more questions or information needed, please let us know. We are happy to serve you! \n
-From
IntaxFin Team \n http://www.intaxfin.com \n
Like us on Facebook \n
Follow us on Twitter \n
Connect with us on LinkedIn \n
------------------------------------------------------------------------------------------------- e-mail was automatically sent by IntaxFin Administration Directory and is for your reference. Please do not reply to this e-mail address.
Powered by HexCode Technologies Pvt. Ltd.
EOD;
$headers = "From: $emailFeild\r\n";
$header = "From: $noreply#intaxfin.com\r\n";
$success = mail($webMaster,$emailSbuject,$body,$headers);
$success1 = #mail($emailFeild,$emailSbuject2,$body2,$header);
/*Result*/
$theResults = <<<EOD
EOD;
echo "$theResults";
header("Location: http://www.intaxfin.com/thankyou.html");
exit;
?>

You cannot display images on text/plain emails as shown above. You must send it as text/html.
So you first have to extend your headers like this:
$header = "From: $noreply#intaxfin.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
Then you must update your mailcontent replacing \n or linebreaks with html tags <br> or even <p>
Then you also can include image tags having the image you want to show in the email
<img src="http://www.yourserver.com/myimages/image1.jpg">
This will be downloaded from your webserver when recipient opens it.
.
BUT the much better way will be to use phpMailer Class
Using this, you will be able to include any images IN your email, without need to download it from any website. It is easy to learn and absolutely customizable.
By the way: You should use quotation marks for your $body and $body2 values...
$body= "<<<EOD
Contact Form Details of $nameFeild
Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n"

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<html><head>
<title>Your email at the time</title>
</head>
<body>
<img src=\"http://www.myserver.com/images_folder/my_image.jpg\">
</body>"
mail($email_to, $email_subject , $message,$headers);

Related

I need senders email id in email subject

My php script is running well but i want to send senders address in email subject .Please guide me how to do it.
Please tell me what should i write in "$emailSbuject = "New Subscription from $emailFeild\r\n";"
This is my php script:
<?php
/* subject and email varialbles*/
$emailSbuject = "New Subscription from $emailFeild\r\n";
$webMaster = 'help#sample.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/
$emailFeild = $_POST['email'];
// admin message body
$body= <<<EOD
New subscriber is $emailFeild
EOD;
$textMessage = <<<EOD
<p style="margin-left:5px;font-family:Calibri"><img alt="" src="http://www.intaxfin.com/images/Intaxfin_logo.png"></p>
<p style="font-family:Calibri">Thank you for subscribing with us. Somebody will get back to you as soon as possible.</p>
<p style="font-size:x-small;color:#0099FF;font-family:Calibri">This e-mail was automatically sent by Administration Directory and is for your reference. Please do not reply to this e- mail address.<br>
Powered by sample</p>
EOD;
$headers = "From: $emailFeild\r\n";
$header = "From: $noreply#sample.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
$success = mail($webMaster,$emailSbuject,$body,$headers);
$success1 = #mail($emailFeild,$emailSbuject2,$textMessage,$header);
/*Result*/
$theResults = <<<EOD
EOD;
echo "$theResults";
header("Location: thankyousubscribe.html");
exit;
?>
$emailFeild = $_POST['email'];
$emailSbuject2 = "New Subscription from $emailFeild";
NOTE : $client has been initiated with $emailFeild variable which is initiated after that line. Please initiate the variable first and then use it.

how to inject confirmation text (HTML) back into webpage, (below the submission form) from a php script?

I have a form in my webpage that sends data submitted by the user to an email address. i.e. a contact form. I know how to open a new page to inform the user that the data has been fired off to the email address. However I do not want to open a new page, I just want to inject a simple Email Sent! text below the actual form for the user; instead of redirecting to a new page.
I have absolutely no idea how to achieve this in PHP. I have all the basics of the process script set up here;
<?php
/*--/ subject & email variables /--*/
$emailSubject = 'Email Title';
$webMaster = 'php.test#outlook.com';
/*--/ gathering data variables /--*/
$firstField = $_POST['first_Name'];
$lastField = $_POST['last_Name'];
$emailField = $_POST['email'];
$telField = $_POST['phone'];
$selectField = $_POST['select'];
$enquiryField = $_POST['enquiry'];
$body = <<<EOD
<br><hr><br>
First Name: $first_Name <br>
Last Name: $last_Name <br>
Email: $email <br>
Tel: $phone <br>
I heard about you from; $select <br>
Enquiry: $enquiry <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster,$emailSubject, $body, $headers);
?>
If anyone can help I would be thankful.

image in email just printing url

I have a simple php email script where I wish to include an image at the bottom. When I add the image tags like below the email just shows <img src="http://domain.com/images/logo.png" /> instead of the actual image. Any ideas why?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: info#domain.com\n";
$usermessage =
"
Thank you for joining our mailing list.
We hope to see you very soon!
Address 1
Address 2
<img src=\"http://domain.com/images/logo.png\" />
";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
$fh = fopen("email.xml", "a");
fwrite($fh, "$email\r\n");
fclose($fh);
?>
You're not passing the Content-Type header with the right message. $headers does contain the right header, but it is sent with a plain text message, whereas $userheaders does not contain the Content-Type header, but the message associated with it does contain some HTML
Replace
$userheaders = "From: info#domain.com\n";
with
$userheaders = "From: info#domain.com\r\n";
$userheaders = "Content-type: text/html\r\n";
and it should work perfectly
This is a word press plugin but if you delete everything BUT the XmailBaby class it should work for you nicely.
That code is a nice piece of work that sends emails very good.
It is just a basic version but it should be enough for you.
Take a look through the code, you might find it interesting.
http://plugins.svn.wordpress.org/xmail-the-right-way/trunk/xmail.php
You need to specify html headers. Rather than do this yourself, you can use a well-established method that supports sending HTML emails, such as PHPMailer:
http://phpmailer.worxware.com/

html link in php mail?

So I have this line in my php form processor:
$automessage = 'Thanks for requesting a sample from us! We have received your information, so please expect your sample shortly. In the meantime, be sure to connect with us on Facebook!';
But the link still shows up as plain text, even though I have this header:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Is my formatting for the link incorrect?
EDIT: Here is the entire script:
<?php
// CLIENT INFORMATION
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$company = $_POST['company'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
// MODIFY THE FOLLOWING SECTION
// your name
$recipientname = "company";
// your email
$recipientemail = "me#company.com";
// subject of the email sent to you
$subject = "Sample Request for $recipientname";
// send an autoresponse to the user?
$autoresponse = "yes";
// subject of autoresponse
$autosubject = "Thank you for your sample request!";
// autoresponse message
$automessage = 'Thanks for requesting a sample from company! We have received your information, so please expect your sample shortly. In the meantime, be sure to connect with us on Facebook and Twitter!';
// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us. We will get back to you as soon as possible.";
// END OF NECESSARY MODIFICATIONS
// format message
$message = "New sample request for $recipientname:
<br>
<br>
First Name: $firstname
<br>
Last Name: $lastname
<br>
Email: $email
<br>
Company: $company
<br>
Address: $address
<br>
City: $city
<br>
State: $state
<br>
Zip: $zip
<br>
Phone: $phone
<br>
--
<br>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: company <me#company.com>' . "\r\n";
// send mail and print success message
mail($recipientemail, $subject, $message, $headers);
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
header("Location: thank-you-sample.php");
?>
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
# You've forgotten to include the HTML-header here.. ^

how to format message body of email?

i have developed a simple php contact form, that's working fine, but i am unable to format the body of the message as per my requirement, my code is given below, i am getting mail in a single line format,
where i want every information on a new line like this
"Name: Syed Sheeraz Ahmed
Contact No: 03453594552
Email: abc#abc.com
Address: R-47, Sector 9, North city.
Requirement: hello how are you"
<?php
$to = "sheery_1#hotmail.com";
$subject = "From Website Contact Form";
$name = $_REQUEST['name'] ;
$contact = $_REQUEST['contact'] ;
$address = $_REQUEST['address'] ;
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Contact No: ".$_POST["contact"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Address: ".$_POST["address"]."<br>";
$MESSAGE_BODY .= "Requirement: ".nl2br($_POST["message"])."<br>";
$message = $_REQUEST['message' + 'address' + 'contact'] ;
$from = $_REQUEST['email'] ;
$headers = "From:" . $from;
mail($to,$subject,$MESSAGE_BODY,$headers);
echo "Mail Sent.";
?>
You want a new line (\n) not an HTML line break (<br>) since your email isn't marked as having an HTML body (and emails that have HTML bodies should really have multipart MIME bodies with both plain text and HTML versions since "HTML only" is a nice flag for spam detectors).
As you are using html tag in your email content.
Set the content- type text/html in the header of your mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
OR
you can save yourself from this type of problems using phpmailer
If your email is sending as text then the tags will do nothing. Try using a new line character for example:
$MESSAGE_BODY = "Name: ".$_POST["name"]."\n";
That should sort your problem.
in above example <br> is printed after the variable printed, why? how to remove <br>
for example:
$_Post["name"] has value "jhon".
it prints: jhon<br>

Categories