This question already has answers here:
How to remove "via" and server name when sending mails with PHP?
(5 answers)
Closed 8 years ago.
i'm using Cpanel in Hostgator and PHP to send the mail. when i use this code i always receive mail via mail as "birkin.websitewelcome.com" . when i send mail through joomla "via" mail id is not added. i don't want to display "birkin.websitewelcome.com" in the mails.
is there any code to be added in mail.php
mail.php
$guest_ip = $visitor_location['IP'];
$guest_country = $visitor_location['CountryName'];
$guest_city = $visitor_location['CityName'];
$guest_state = $visitor_location['RegionName'];
$name=mysql_real_escape_string($_GET['name']);
$email=mysql_real_escape_string($_GET['email']);
$subject1=mysql_real_escape_string($_GET['subject']);
$messag=mysql_real_escape_string($_GET['message']);
$to = "id#mydomain.com";
$subject = 'Mail From Contact Page - Surabi Institutions';
$headers = "From: info#mydomain.org \r\n";
$headers .= "Reply-To:info#mydomain.org \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<div style="border: 1px solid #292929; margin:0 auto; height:auto;
width:70%; color:#808080; padding: 0% 10%;">';
$message .= '<h3>Mail From Contact Page</h3>';
$message .= '<strong>Name</strong>:'.$name.'<br>';
$message .= '<strong>Email</strong>:'.$email.'<br>';
$message .= '<strong>Subject</strong>:'.$subject1.'<br>';
$message .= '<strong>Message</strong><br>'.$messag.'<br><br /><br /><br /> </div>';
$message .= '<div style="border-top:1px solid #cacaca; margin-top:50px; height:auto; color:#faa;">';
$message .= '<b>Visitor IP</b> -'.$guest_ip.'<br>';
$message .='<b>Visitor City</b> -'.$guest_city.'<br>';
$message .='</div> ';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers))
{
echo "<script type='text/javascript'> alert('Thank you. We will be in touch with you very soon.'); window.location='index.php';</script>";
}
else
{
echo "<script type='text/javascript'> alert('Mail Sending Failed Please Try Again'); history.back();</script> ";
}
you can use this code.
$to = ""test#gmail.com;
$from = "info#test.com";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
// now lets send the email.
mail($to, $subject, $message, $headers);
Related
I'm using PHP 7.4.30 and I'm totally new to PHP.
$subject ="My subject";
$message = '<html><body>';
$message .= '<div style="text-align: center; width: 100%; background-color: #fff;">';
$message .= '<div class="info"> </div>';
$message .= '<table style="text-align: justify; margin: auto; background-color: #ebebeb; border: 1px solid #e7e7e7; width: 600px;" cellspacing="0" cellpadding="0" bgcolor="#ebebeb" align="center">';
$message .= '<tbody>';
$message .= '<tr style="line-height: 0px;">';
$message .= '<td style="line-height: 0';
$from = "My website<robot#website.com>";
$replyto = "website#website.com";
$headers = 'Content-Type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: '. $replyto . "\r\n";
$headers .= 'Bcc: xxx#xxx.com';
$message = str_replace("\n.", "\n..", $message);
mail($to, $subject, $message, $headers);
Looking at the delivery track from the server, I see the error message:
"message has lines too long for transport"
Can anyone help?
I have recently faced this issue. An easy solution to this issue is replacing this line
$message = str_replace("\n.", "\n..", $message);
with
$message = wordwrap($message, 70,"\r\n");
$mail_body = '<html>
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
<h3><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0">
</h3>
<p>Hello ' . $name . ',</p>
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p>
<p>Grill on the Rock </p>
<hr>
<p>To opt out of receiving this newsletter, click here and we will remove you from the listing immediately.</p>
</body>
</html>';
$to = "$email";
$subject = "Example Grill on the Rock Email";
$from="info#grillontherock.com";
$mail_result = mail($to, $subject, $mail_body, "From:".$from);
}
if($mail_result){
echo "Email has been sent successfully";
}
I am having problem with sending email with php and html.
This code works perfectly fine but the email I am getting is
but when I use double quotation for html file php code greys out for some reason.
$mail_body = "<html>
<body style="background-color:#CCC; color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
<h3><img src="http://i.imgur.com/OODKT9h.png" alt="GR" width="194" height="123" border="0">
</h3>
<p>Hello ' . $name . ',</p>
<p>You can make this out to be just like most any web page or design format you require using HTML and CSS.</p>
<p>Grill on the Rock </p>
<hr>
<p>To opt out of receiving this newsletter, click here and we will remove you from the listing immediately.</p>
</body>
</html>";
$to = "$email";
$subject = "Example Grill on the Rock Email";
$from="info#grillontherock.com";
$mail_result = mail($to, $subject, $mail_body, "From:".$from);
}
if($mail_result){
echo "Email has been sent successfully";
}
a bit new to php and html and I could not find similar problem at the moment.
Also, Is it possible to have email as html form and bring that html through send php file?
You need to set Content-Type to text/html in mail headers
Example headers with Content Type:
$headers = "From: danny#danny.domain\r\n";
$headers .= "Reply-To: no-reply#danny.domain\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
then
$mail_result = mail($to, $subject, $mail_body, $headers);
#edit.
Also check exaple #4 at:
http://php.net/manual/en/function.mail.php
With second html you are having problem with double quotes, because you are using double quotes inside the html, try to escape them. Try this:
or try the link below:
What is the difference between single-quoted and double-quoted strings in PHP?
You need to set Content-Type to text/html in mail headers to send your mail as html mail.
Example headers:
$headers = "From: mymail#gmail.com\r\n";
$headers .= "Reply-To: no-reply#mymail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
finally after your content you need to send mail like the following.
$mail_result = mail($to, $subject, $mail_body, $headers);
Then for your double quotes problem : here you used double quotes inside double quotes. if that so you need to escape it with "/".
i am trying to figure out writing html in php file. it seems that php does not recognise all the html tag like font, img. it gave an error. I tried echo 'html stuff'; but it dont seem to work as well.
I have left out the other $var declaration in the code below. the script is working except when i tried to add font size or img tags.
<?php
header("Content-type: html");
$message = "
<!DOCTYPE html>
<html>
<head>
<title>New Loan Enquiry</title>
</head>
<body>
<h2><strong>Time of Enquiry: $today</strong></h2>
Name: $name<br>
Email: $email<br>
Contact: $contact<br>
Buy_Stage: $buystage<br>
Property Type: $pty_type<br>
Property Stage: $pty_stage<br>
Purchase Price: $purchaseprice<br>
Loan Amount: $loanamt<br>
Rate Type: $rate_type<br>
Comments: $comments<br><br>
</body>
</html>
";
mail($to,$subject,$message,$headers);
?>
where did i go wrong? It recognize h2 but not h1 or h3.
do i have to do like
echo ' html';
for each html code line?
Please check mail() in documentation.
To send email with html content you need to do this way:
<?php
$to = 'aidan#example.com';
// subject
$subject = 'subject of email';
// message
$message = 'some html content...';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
and you don't need to use:
header("Content-type: html");
you need to add
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <from#example.com>' . "\r\n";
$headers .= 'Cc: cc#example.com' . "\r\n";
and remove
header("Content-type: html");
I find it best to style Html email in php by using tables and inline styles like below. here is a link to reference. Link, Sadly internal and external style sheets don't always work across different email clients.
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$message = '<html>';
$message .= '<head>';
$message .= '<title>New Loan Enquiry</title>';
$message .= '</head>';
$message .= '<body>';
$message .= '<h2><strong>Time of Enquiry: $today</strong></h2>';
$message .= '<img src="http://YOUR_IMAGE_URL"/>;
$message .= '<table width="auto" border="0" cellspacing="3px" cellpadding="0">';
$message .= '<tr><td><strong>Name:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$name</td></tr>';
$message .= '<tr><td><strong>Email:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$email</td></tr>';
$message .= '<tr><td><strong>Contact:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$contact</td></tr>';
$message .= '<tr><td><strong>Buy_Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$buystage</td></tr>';
$message .= '<tr><td><strong>Property Type:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_type</td></tr>';
$message .= '<tr><td><strong>Property Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_stage</td></tr>';
$message .= '<tr><td><strong>Purchase Price:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$purchaseprice</td></tr>';
$message .= '<tr><td><strong>Loan Amount:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$loanamt</td></tr>';
$message .= '<tr><td><strong>Rate Type:</strong></td>';
$message .= '<td>\$rate_type</td></tr>';
$message .= '<tr><td><strong>Comments:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$comments</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
mail($to,$subject,$message,$headers);
?>
I am trying to use the following in my contact us form to receive nicely formatted html email from my visitors:
$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail</caption>';
$message .='<tr><td width="200"><strong>Date</strong></td><td width="600" style="border:1px solid #ccc;">'.$todayis.'</td></tr>';
$message .='<tr><td width="200"><strong>From</strong></td><td width="600" style="border:1px solid #ccc;">'.$name.'</td></tr>';
$message .='<tr><td width="200"><strong>Email</strong></td><td width="600" style="border:1px solid #ccc;">'.$email.'</td></tr>';
$message .='<tr><td width="200"><strong>Subject</strong></td><td width="600" style="border:1px solid #ccc;">'.$recipient.'</td></tr>';
$message .='</table>';
$message .= '<div style="width:770px;background:#eee;padding:15px;">';
$message .= '<div style="font-weight: bold; font-size: 18px;padding-bottom: 10px;">Your Message</div>';
$message .= $message;
$message .= '</div>';
$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail Data</caption>';
$message .='<tr><td width="200"><strong>IP Address</strong></td><td width="600" style="border:1px solid #ccc;">'.$ip.'</td></tr>';
$message .='<tr><td width="200"><strong>Browser Info</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpagent.'</td></tr>';
$message .='<tr><td width="200"><strong>Referral</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpref.'</td></tr>';
$message .='</table>';
$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$sent = mail($to, $subject, $message, $headers);
The problem I have is that when I use text/html the email shows as sent but I am not getting it, when I am changing it to text/plain everything works fine except that I get everything in plain text without any HTML formatting.
I am on my own dedicated Apache server, running Plesk 12.0.18 and CentOS6.6 do I need to configure anything on the server? I have tried to configure the email to receive everything in HTML format, but seems like it did not work.
Any help is appreciated.
Php Html email
<?php
$to = "abc#gmail.com";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . '
<h1>this is a heading</h1>
</body>
</html>';
//$headers = "From: abc#gmail.com";
//$headers .= "Content-type: text/html";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <abc#gmail.com>' . "\r\n";
mail($to, $subject, $mail_body, $headers);
?>
Enjoy this code
I designed an HTML page and then converted it to use in PHP in order to send an HTML email.
$message = '<!DOCTYPE html>';
$message .= '<html>';
$message .= '<body bgcolor="#E8E8E8 ">';
$message .= '<table bgcolor="white" >';
$message .= '<tr>';
$message .= '<td style="font-family:\'Helvetica Neue\',Helvetica,Arial,sans-serif;">';
$message .= '<img src="#" width="200px">';
$message .= 'This is a test page.';
$message .= '</td>';
$message .= '</tr>';
$message .= '</table>';
$message .= '</body>';
$message .= '</html>';
$to = "you#example.com";
$subject = "Pulling my hair out";
$headers = "From: me#example.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$message,$headers);
Even though it looks perfect as a stand-alone html page (and I even made a test php page that echoes the $message array, and it still looks perfect) it will have weird things wrong with it in the email (after it's sent).
Sometimes there will be a random ! in the middle of the text. Sometimes the styling in a tag will not show up in the email (when I 'inspect' the html of the email). It seems erratic.
What am I missing here?
You can make one page emailresetTemplate.php
In this page write these line's
<?php ob_start();?>
//do your html stuff here ....... Example Below..........
<div style="width:698px; margin:0 auto; position:relative;">
<div>
<div style="background:url(<?php echo ABSOLUTE_PATH; ?>images/email/restpass/header.png) no-repeat; width:680px; height:127px; margin:0 0 0 10px;"></div>
</div>
<?php
$contents = ob_get_contents();
ob_clean();
include("emailresetTemplate.php");
$to = $email;
$subject = 'Your Password Reset Request';
$message = $contents;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: email#example.com' . "\r\n" .
'Reply-To: email#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(#mail($to, $subject, $message, $headers)){
print "An email containing the password has been sent to you at " . $row["eMail"];
} else {
echo("No such login in the system. please try again.");
}
?>
</div>