I am using this script to send an email…
function secure($sec) {
return mysql_real_escape_string( htmlspecialchars ($sec) );
}
function sendHTMLemail($to, $subject, $from, $body) {
if (ereg("(.*)< (.*)>", $from, $regs)) {
$from = '=?iso-8859-8?B?'.base64_encode($regs[1]).'?= < '.$regs[2].'>';
} else {
$from = $from;
}
$headers = "From: $from\\r\
";
$headers .= "MIME-Version: 1.0\\r\
";
$boundary = uniqid("HTMLEMAIL");
$headers .= "Content-Type: multipart/alternative;".
"boundary = $boundary\\r\
\\r\
";
$headers .= "This is a MIME encoded message.\\r\
\\r\
";
$headers .= "--$boundary\\r\
".
"Content-Type: text/plain; iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode(strip_tags($body)));
$headers .= "--$boundary\\r\
".
"Content-Type: text/html; charset=iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode($body));
$result = mail($to,'=?iso-8859-8?B?'.base64_encode($subject).'?=',"",$headers);
return $result;
}
if (isset($_POST['Name']) && isset($_POST['Phone']) && isset($_POST['property']) && isset($_POST['email']) && isset($_POST['region']) && isset($_POST['Select1']))
{
$Name = secure($_POST['Name']);
$Phone = secure($_POST['Phone']);
$property = secure($_POST['property']);
$email = secure($_POST['email']);
$region = secure($_POST['region']);
$Select1 = secure($_POST['Select1']);
$success = $error=""
$to = "mymail@mymail.com";
$body = "blabla";
$subject = "blabla";
if (sendHTMLemail($to, $subject, $email, $body))
$success = "Succesfully sent!";
else
$error = "Error!";
}
and I keep getting error’s no matter if I change the mail/body/subject
whats wrong with that?
It would be helpful if you shared those errors…
Mandes
February 27, 2011, 5:37pm
3
your putting your content string into $headers
your not passing any content to the mail
the mail() config should be
mail($to, $subject, $message, $headers);
I dont get any errors only the
“Error!” text from my script telling me sendHTMLEmail failed…
if (sendHTMLemail($to, $subject, $email, $body))
$success = "Succesfully sent!";
else
$error = "Error!";
Mandes, its still not working… :\
Show us the latest version with the changes you implemented following Mandes recommendations please.
mmm this is wierd when im trying to use this script on my hosting package at beastserv(http://www.beastserv.com/ ) host it works perfect…
but when im trying to run it on my hosting package at https://manage.ixwebhosting.com
it doesnt send me the message… how is that possible?
There’s not much point telling us the symptoms and avoiding our questions/requests is there. It won’t help you or us unless you’re willing to provide more detailed information.
IIRC ixwebhosting use windows - I know someone who used them years ago. That being the case you may have a problem as I suspect you may be using a SMTP server connecting to gmail to send email and as I’ve already told you gmail is picky about allowing altered from headers because of its anti-spam policy.
You do not have to show us the code but it will certainly help.
I have no problem in showing you the code I just thought you could help me without it.
any way this is the code:
http://pastebin.com/2gag5nYT
- you may not understand some of words since they are written in Hebrew…
but the code is the same
Thank you very much for you help and time :)!
Generally no, we need to see code so that we can rule out errors etc. If we ask to see the code there is no point thinking to yourself that you don’t need to show it to us - it’s almost rude!
Secondly, please can you post the code HERE in this topic inside
tags please. That site you've posted it on doesn't format the code very well and it makes it hard to understand.
Finally, Hebrew? - Doesn't worry me. If I can help, I will but I can't promise to solve the problem but if I can I will. I think everyone here will say the same.
I’m sorry if I was sound rude to you…
here you go:
<?php
function secure($sec) {
return htmlspecialchars ($sec);
}
function sendHTMLemail($to, $subject, $from, $body) {
if (ereg("(.*)< (.*)>", $from, $regs)) {
$from = '=?iso-8859-8?B?'.base64_encode($regs[1]).'?= < '.$regs[2].'>';
} else {
$from = $from;
}
$headers = "From: $from\\r\
";
$headers .= "MIME-Version: 1.0\\r\
";
$boundary = uniqid("HTMLEMAIL");
$headers .= "Content-Type: multipart/alternative;".
"boundary = $boundary\\r\
\\r\
";
$headers .= "This is a MIME encoded message.\\r\
\\r\
";
$headers .= "--$boundary\\r\
".
"Content-Type: text/plain; iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode(strip_tags($body)));
$headers .= "--$boundary\\r\
".
"Content-Type: text/html; charset=iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode($body));
$result = mail($to, $subject, $message, $headers);
return $result;
}
if (isset($_POST['Name']) && isset($_POST['Phone']) && isset($_POST['property']) && isset($_POST['email']) && isset($_POST['region']) && isset($_POST['Select1']))
{
$Name = secure($_POST['Name']);
$Phone = secure($_POST['Phone']);
$property = secure($_POST['property']);
$email = secure($_POST['email']);
$region = secure($_POST['region']);
$Select1 = secure($_POST['Select1']);
$success = $error="";
$to = "danrevah@hotmail.com";
$subject = "נוצר איתך קשר מהאתר הראל נדלן";
$body = "<html><body><center><div align=\\"right\\">שם מלא: ".$Name."<br>מספר הטלפון שהוזן: ".$Phone."<br><br>כתובת המייל שהוזנה: ".$email."<br>סוג הנכס: ".$property."<br>אזור מבוקש:".$region."<br>מיועד ל: ".$Select1.'</div></center></body></html>';
if (sendHTMLemail($to, $subject, $email, $body))
$success = "ההודעה נשלחה בהצלחה!";
else
$error = "אירעה שגיאה בשליחת הדואר. אנא נסה שנית מאוחר יותר";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<!--
Created by Artisteer v2.3.0.23326
Base template (without user's data) checked by http://validator.w3.org : "This page is valid XHTML 1.0 Transitional"
-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>הראל נדל"ן </title>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
<style type="text/css">
.style1 {
font-size: medium;
color: #545454;
}
.style2 {
text-align: right;
}
.style3 {
text-align: center;
}
.style5 {
color: #292929;
}
.style6 {
font-family: Georgia, "Times New Roman", Times, Serif;
color: #292929;
height: 1%;
text-align: center;
margin: 0;
}
.style7 {
margin-bottom: 0px;
}
.style9 {
font-family: Arial;
}
.style11 {
text-decoration: none;
margin: 0.2em 0;
padding: 0;
font-weight: normal;
font-style: normal;
letter-spacing: normal;
word-spacing: normal;
font-variant: normal;
text-decoration: none;
font-variant: normal;
text-transform: none;
text-align: center;
text-indent: 0;
line-height: inherit;
font-family: Arial;
font-size: large;
font-style: normal;
font-weight: bold;
color:white;background-color:silver;
}
.style12 {
font-family: Arial;
font-size: small;
letter-spacing: normal;
word-spacing: normal;
font-style: normal;
font-weight: normal;
text-decoration: none;
color: #B0B0B0;
text-align: center;
margin: 1em;
}
</style>
</head>
<body>
<div id="art-main" class="style3">
<div class="art-Sheet">
<div class="art-Sheet-tl"></div>
<div class="art-Sheet-tr"></div>
<div class="art-Sheet-bl"></div>
<div class="art-Sheet-br"></div>
<div class="art-Sheet-tc"></div>
<div class="art-Sheet-bc"></div>
<div class="art-Sheet-cl"></div>
<div class="art-Sheet-cr"></div>
<div class="art-Sheet-cc"></div>
<div class="art-Sheet-body">
<div class="art-Header">
<div class="art-Header-png"></div>
<div class="art-Header-jpeg"></div>
</div>
<div class="art-contentLayout">
<hr noshade="noshade" />
<div class="art-content">
<div class="art-Post" style="left: 0px; top: 0px">
<div class="art-Post-body">
<div class="art-Post-inner">
<div class="art-PostContent">
<p class="style2" dir="RTL">
<span lang="HE" style="line-height: 115%; font-family: "Arial","sans-serif"" class="style1">
הראל נדל"ן הינה חברת תיווך והשקעות
בנדל"ן שפועלת במקצועיות ובאמינות
גבוהה ומבטיחה מענה ויחס אישי ומיידי
לכל פנייה שלכם. <br />
החברה מעמידה לרשות לקוחותיה ניסיון
רב וסיוע מקסימאלי באיתור הנכס או
לקוח המתאים לדרישות שלכם, בהשבחת
הנכס שלכם, בשיפוץ ועיצוב בית החדש
שלכם.
לקוחות החברה ילוו באופן אישי על ידי
יועץ מקצועי, אשר ירכז את הדרישות
והצרכים שלכם וייתן לכל אלה מענה
מקצועי ואמין, וזאת בשיתוף פעולה מלא
עם צוות המשרד וצוות מקצועי בתחום.</span><span dir="LTR" style="font-family:"Arial","sans-serif""><o:p></o:p></span></p>
<table class="table" width="100%" style="height: 307px">
<tr>
<td width="33%" valign="top">
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" id="myMovieName" style="width: 450px; height: 294px">
<PARAM NAME=movie VALUE="C:\\Users\\Alon\\Desktop\\harel real estate\\flash\\harel.swf">
<PARAM NAME=quality VALUE=High>
<PARAM NAME=bgcolor VALUE=#ffffff>
<EMBED src="flash/harel.swf" quality=High bgcolor=#ffffff
NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" style="width: 450px; height: 294px">
</EMBED>
</OBJECT>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="art-Post" style="left: 0px; top: 0px">
<div class="art-Post-body">
<div class="style2">
<h2 class="style11">?<span lang="he">
מעוניינים לרכוש נכס להשקעה או למגורים
</span></h2>
<h2 class="style11"><span lang="he">מלאו
את פרטיכם ואחד מנציגינו יחזור
אליכם בהקדם </span></h2>
<div class="style3">
<br />
</div>
<table width="100%">
<tr>
<td>
<img src="images/contact.jpg" width="300" height="180" style="float: left;vertical-align:top;
" /></td>
<td>
<div class="style6">
<div class="style3">
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--
function FrontPage_Form2_Validator(theForm)
{
if (theForm.Name.value == "")
{
alert("Please enter a value for the \\"Name\\" field.");
theForm.Name.focus();
return (false);
}
if (theForm.Name.value.length < 1)
{
alert("Please enter at least 1 characters in the \\"Name\\" field.");
theForm.Name.focus();
return (false);
}
if (theForm.טלפון.value == "")
{
alert("Please enter a value for the \\"טלפון\\" field.");
theForm.טלפון.focus();
return (false);
}
if (theForm.טלפון.value.length > 12)
{
alert("Please enter at most 12 characters in the \\"טלפון\\" field.");
theForm.טלפון.focus();
return (false);
}
var checkOK = "0123456789-.,";
var checkStr = theForm.טלפון.value;
var allValid = true;
var validGroups = true;
var decPoints = 0;
var allNum = "";
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch == ".")
{
allNum += ".";
decPoints++;
}
else if (ch == "," && decPoints != 0)
{
validGroups = false;
break;
}
else if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter only digit characters in the \\"טלפון\\" field.");
theForm.טלפון.focus();
return (false);
}
if (decPoints > 1 || !validGroups)
{
alert("Please enter a valid number in the \\"טלפון\\" field.");
theForm.טלפון.focus();
return (false);
}
if (theForm.email.value == "")
{
alert("Please enter a value for the \\"email\\" field.");
theForm.email.focus();
return (false);
}
if (theForm.email.value.length < 1)
{
alert("Please enter at least 1 characters in the \\"email\\" field.");
theForm.email.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan -->
<?php echo $success; echo $error; ?><br>
<form action="index.php" method="post">
<!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="1" -->
<input name="Name" dir="rtl" value="שם מלא" class="style7" size="20"/>
<br />
<br />
<!--webbot bot="Validation" s-data-type="Number" s-number-separators=",." b-value-required="TRUE" i-maximum-length="12" -->
<input name="Phone" type="text" dir="rtl" value="מס' טלפון" maxlength="12" style="height: 20px" /><br />
<br />
</span><!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="1" --><input name="email" type="text" dir="rtl" value="כתובת מייל" /><br />
<br />
<select name="property" dir="rtl" style="width: 66px">
<option>דירת מגורים
</option>
<option>קרקע
</option>
<option>נכס מסחרי
</option>
</select> :
<span lang="he">סוג
הנכס</span><br />
<br />
<select name="region" dir="rtl" style="width: 55px">
<option>צפון</option>
<option>מרכז</option>
<option>דרום</option>
</select> : <span lang="he">איזור
מבוקש</span><br />
<span lang="he"><br />
<select name="Select1" dir="rtl" style="width: 72px">
<option>מגורים</option>
<option>השקעה</option>
</select> : מיועד ל
<br />
<br />
<input type="submit" value="שליחה"
style="color: #ffffff;
background-color:#000000"/>
<br />
<br />
<br />
</span>
</form>
</div>
</div>
<td>
<img src="images/real-estate-finance1.jpg" width="300" height="180" /></td>
</td>
</tr>
</table>
<div class="cleared"></div>
</div>
<div class="cleared"></div>
</div>
</div>
</div>
</div>
<div class="cleared"></div><div class="art-Footer">
<div class="art-Footer-inner">
<a href="#" class="art-rss-tag-icon" title="RSS"></a>
<div class="art-Footer-text">
<p><span class="style9"> <span lang="he">זכויות
שימוש</span> | </span><span class="style9"> |
</span><span lang="he" class="style9">
<a href="mailto:ddtech@netvision.net.il">
צור קשר</a></span><span class="style9"><br />
<span lang="he">כל הזכויות שמורות להראל נדל"ן
</span> © 2011 </span></p>
</div>
</div>
<div class="art-Footer-background"></div>
</div>
<div class="cleared"></div>
</div>
</div>
<div class="cleared"></div>
<p class="style12" style="height: 13px"> <strong>נבנה ע"י אלון כדורי</strong></p>
</div>
</body>
</html>
Jay_P
February 27, 2011, 8:51pm
12
You’re still not giving the mail() a $message argument…
Mandes
February 27, 2011, 9:26pm
13
and still putting your body text and MIME boundaries inside the $headers
you need to change all the $headers
$headers .= "This is a MIME encoded message.\\r\
\\r\
";
$headers .= "--$boundary\\r\
".
"Content-Type: text/plain; iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode(strip_tags($body)));
$headers .= "--$boundary\\r\
".
"Content-Type: text/html; charset=iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$headers .= chunk_split(base64_encode($body));
to make the MIME message
$message = "This is a MIME encoded message.\\r\
\\r\
";
$message .= "--$boundary\\r\
".
"Content-Type: text/plain; iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$message .= chunk_split(base64_encode(strip_tags($body)));
$message .= "--$boundary\\r\
".
"Content-Type: text/html; charset=iso-8859-8\\r\
".
"Content-Transfer-Encoding: base64\\r\
\\r\
";
$message .= chunk_split(base64_encode($body));
Thank you very much guys that solved me the problem… !