Send HTML links in php mail message - php

I am trying to send a html link in mail using php. But I am getting the full text of html in the mail. Below is the code what I have tried . But it is not working. Any help is appreciated.
$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail#gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
Below is what I am getting in mail with tag
http://www.google.com'> Click Here

I've checked with your code..
Seems like you are making a simple mistake..
You are not concatenating your code.. you are re assigning your header at line 3
Your Code
$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail#gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
Updated Code on headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from;
Update your header and try again!
Thanks! Have a nice day!

Working code with template paste and run
<?
$to = $send_to;
$subject = $mail_subject;
$message .= '<div style="margin:0;font-weight:lighter;background:#f0f4f7;">
<table class="m_6501530908114331344layout" style="font-family:Helvetica,Arial,sans-serif;background:#f0f4f7;width:100%">
<tbody><tr>
<td>
<table cellspacing="0" class="m_6501530908114331344page-container" width="505" align="middle" style="font-family:Helvetica,Arial,sans-serif;border-spacing:0;background-color:#fff;max-width:505px!important;display:block!important;margin:25px auto!important;clear:both!important">
<tbody><tr class="m_6501530908114331344header" style="background-color:rgba(218, 23, 23, 0.03);">
<td class="m_6501530908114331344row" style="border-left:1px solid #e7e7e7;border-right:1px solid #e7e7e7;border:none;padding:20px 35px">
<img alt="lasaioffice" height="80" width="300" src="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png" class="CToWUd">
</td>
</tr>
<tr class="m_6501530908114331344subject" style="background-color:#fff">
<td class="m_6501530908114331344primary-message" style="padding:20px 35px 0">
<p style="margin:20px 0;line-height:1.45">Hi google </p>
<h2 class="m_6501530908114331344centered" style="font-size:24px;font-weight:bold;margin:0;margin-bottom:30px;display:block;text-align:center;margin-bottom:0;color:#eb2028;">
Just one more click
</h2>
<table class="m_6501530908114331344email-btn" style="font-family:Helvetica,Arial,sans-serif;background:#eb2028;padding:10px">
<tbody><tr>
<td>
Activate Account
</td>
</tr>
</tbody>
</table>
<p style="margin:20px 0;line-height:1.45">
<strong style="font-weight:bold">
Kind Regards, <br>
The google Team
</strong>
</p>
</td>
</tr>
<tr class="m_6501530908114331344footer" style="color:#7f8da0">
<td class="m_6501530908114331344footer-tagline" style="padding:0 35px">
<hr class="m_6501530908114331344footer-line-break" style="margin-bottom:35px;border:0;border-bottom:1px solid #d3dbe3">
<p class="m_6501530908114331344small" style="font-size:12px">
<strong style="font-weight:bold">
<a style="color:#eb2028;" href="http://google.com">google</a> -
The leading marketplace selling google.
</strong>
</p>
<p class="m_6501530908114331344small" style="font-size:12px">
This account notification was sent to you because you are a google user.
Should you have any questions, you are welcome to email us.
</p>
</td>
</tr>
<tr class="m_6501530908114331344footer" style="color:#7f8da0">
<td class="m_6501530908114331344footer-links" style="padding:20px 35px 45px">
<p class="m_6501530908114331344small" style="font-size:12px">
Copyright © 2017 | google Pty Ltd. All rights reserved.
</p>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<img src="" alt="" width="1" height="1" border="0" style="height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="CToWUd"><div class="yj6qo"></div><div class="adL">
</div></div>';
$header = "From:abc#gmail.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>

Related

image is not embeding in email in php

I am trying to embed the image to the html content of email in php but whenever the email sent it show me broken link of image there. Image is not embeding to the email here is the code
<?php
$to = 'xxxx#xxxx.com';
$subject = "Beautiful HTML Email using PHP by CodexWorld";
$htmlContent = '
<html>
<head>
<title>Welcome to CodexWorld</title>
</head>
<body>
<h1>Thanks you for joining with us!</h1>
<table cellspacing="0" style="border: 2px dashed #FB4314; width: 300px; height: 200px;">
<tr>
<th>Name:</th><td>CodexWorld</td>
</tr>
<tr style="background-color: #e0e0e0;">
<th>Email:</th><td>contact#codexworld.com</td>
</tr>
<tr>
<th>Website:</th><td>www.codexworld.com</td>
</tr>
<tr>
<th>image:</th><td><img src="http://xxxxxxxxxxxxx.com/email/1.png"/></td>
</tr>
</table>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: xxxx#xxxxx.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Please guide me where is I am wrong

How to send mail using php by insert html into mail content? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
How to send mail using php by insert html into mail content ?
I tried to insert html code inner $message, When i test it's show error
like this Parse error: syntax error, unexpected 'margin' (T_STRING)
How can i do ?
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style="margin: 0; padding: 0;">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<img src="http://i.stack.imgur.com/Jy9QUm.jpg"/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>
You have an issue with wrapping your $body string try this
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>

Sending html with email body

I am trying to insert and send email with html body but the received email is pure html text.I've added correct headers but seems that they not helping me ( or at least I think are correct one ).
Here is the code
if(isset($_POST['email'])) {
$email_to = "";
$email_subject = "";
$firstname = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // not required
$phone = $_POST['phone'];
$captcha = $_POST['captcha'];
$subject = $_POST['subject']; // required
$email_message = "New email:\n\n";
$email_message .= '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top" bgcolor="#838383" style="background-color:#838383;"><br>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><img src="images/top.png" width="600" height="177" style="display:block;"></td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#d3be6c" style="background-color:#d3be6c; font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000; padding:0px 15px 10px 15px;">
<div style="font-size:24px; color:#555100;"><br>
'.$firstname.'
</div><br>
<div>'.$subject.'</div>
<div>
'.$message.'
'.$email.'
'.$phone.'
</div></td>
</tr>
<tr>
<td align="left" valign="top"><img src="images/bot.png" width="600" height="18" style="display:block;"></td>
</tr>
</table>
<br>
<br></td>
</tr>
</table>
</body>
</html>';
// create email headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}
http://pastebin.com/5aQh0Gvz
You were resetting $headers when setting the From: header:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n". // << note the dot before = that wasn't here before making `$headers` to be resetted
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();

php email from name header based on user name input

What am I doing wrong here. When a user submits the form, it shows up in my inbox with their name as their email address and I would like it to be the name that they input in the form. here is my code.
<?php
//error_reporting(0);
//include("connection.php");
$n=$_POST['name'];
$e=$_POST['email'];
$p=$_POST['phone'];
$t1=$_POST['tot_eth'] ;
$t2=$_POST['tot_tax'];
$t3=$_POST['tot_acct'];
$t4=$_POST['tot_tot'];
$i=1;
while($i<13)
{
${'date' . $i} = $_POST["date$i"] ;
${'seminar'.$i}=$_POST["seminar$i"] ;
${'sponser'.$i}=$_POST["sponser$i"] ;
${'ethics'.$i}=$_POST["ethics$i"] ;
${'tax'.$i}=$_POST["tax$i"] ;
${'acct'.$i}=$_POST["acct$i"] ;
${'t'.$i}=$_POST["total$i"] ;
$i++;
}
//session_start();
$to = "mj#ntatax.com";
$from=$n $e;
$subject = "2015 CPE Verification Form";
// compose headers
$headers = 'From: '. $_POST['name'] . ' <' . $e . '>\r\n' .
'Reply-To:' .$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// compose message
$message ='<html>
<body>
<p>
From Name : '.$n.'<br>
From Email : '.$e.'<br>
Phone Number : '.$p.'<br><br>
</p>
<table cellpadding="5"> <tr>
<td>Date </td>
<td>Seminar Attended and Location </td>
<td>Sponsor </td>
<td>Ethics Hours </td>
<td>Tax Hours </td>
<td>Acct Hours</td>
<td>Total Hours</td>
</tr>
';
for ($i=1;$i<=13;$i++){
$message .='<tr>
<td>'.${'date' . $i}.'</td>
<td>'.${'seminar'.$i}.'</td>
<td>'.${'sponser'.$i}.'</td>
<td>'.${'ethics'.$i}.'</td>
<td>'.${'tax'.$i}.'</td>
<td>'.${'acct'.$i}.'</td>
<td>'.${'t'.$i}.'</td>
</tr>';
}
$message .=' <tr></tr>
<tr>
<td colspan=2>
<td><p style="text-align: right">Total</p></td>
<td>'.$_POST['tot_eth'].'</td>
<td>'.$_POST['tot_tax'].'</td>
<td >'.$_POST['tot_acct'].'</td>
<td >'.$_POST['tot_tot'].'</td> </td>
</tr> </table>
</body>
</html>';
$message = wordwrap($message, 270);
// send email
mail($to,$subject, $message, $headers,"'".'-f '.$from."'");
// mail($to,$subject, $message, $headers,"'".'-f '.$from."'");
session_start();
//$_SESSION['send1']="Thanks For Contacting Us,Your Query Will Be Replied At the Earliest.";
header("location:http://www.waainc.org");
?>

How to send values from html form to mail in table PHP

This what I have I tried to put it in a table just like:
<table>
<tr><td>$_POST['onderwerp']</td></tr>
</table>
This is what I have it sends the mail but it's to messy:
<?php
$to = 'example#gmail.com';
$subject = 'Vraag via de website';
$message = 'Onderwerp:'. $_POST['onderwerp'].'<br /><br />'.$_POST['vraag'].'<br /><br />'.'Telefoonummer:'. $_POST['tel'].'<br /><br />'.'Email:'. $_POST['email'] ;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:<eexample#gmail.com>' . "\r\n";
$headers .= 'The shop<example#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header('Location: contact.html');
?>
I just want to send the variables in a table so that I don't have to search through all the text.
<?php
$to = 'user#example.com';
$subject = 'Vraag via de website';
$msg = "<html>
<head>
<title>Title of email</title>
</head>
<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">
<tr>
<td align=\"center\">Onderwerp</td>
<td align=\"center\"> vraag</td>
<td align=\"center\">Telefoonummer</td>
<td align=\"center\">Email</td>
</tr>
<tr>
<td align=\"center\">".$_POST['onderwerp']."</td>
<td align=\"center\">".$_POST['vraag']."</td>
<td align=\"center\">".$_POST['tel']."</td>
<td align=\"center\">".$_POST['email']."</td>
</tr>
</table>
</body>
</html>";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <me#mysite.com>' . "\r\n";
mail($to, $subject, $msg, $headers);
?>
you could try this using your variables.
$var = 'test';
$var2 = 'test2';
echo '<table border="1">';
echo '<tr><td>' . $var . '</td></tr>';
echo '<tr><td>' . $var . '</td></tr>';
echo '</table>';
this will show the variables in a table, then you can edit the table using css how you want. :)
I suggest that you include swiftmailer.
Swiftmailer makes sure emails get delivered in the Inbox and you can easily include HTML markup in your emails:
Swiftmailer HTML in email
Just download the Swiftmailer Library, include and configure it like this example:
Sending an email in swiftmailer
Let me know if this helps you out!

Categories