This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to execute "Tell a friend" php script, but that is not sending any emails, not to admin, friends, sender. Other emails on same server working fine.
I don't understand why this is not working, as other emails pages like contact us, registration (which send confimation email) all working on same server, please help me..
Html Code:
<table>
<tr>
<td>
<span>Complete the details below to send this link to a friend:</span>
<?php
$refurl = $_SERVER['HTTP_REFERER'];?>
<span><? print $refurl;?></span>
<form name="tellafriend" action="send_group.php" method="post" onSubmit="return checkfields()">
<table>
<tr>
<td> Your name*:</td>
<td> <input name="name" size="30" maxlength="45"> </td>
</tr>
<tr>
<td>Your email*:</td>
<td><input name="email" size="30" maxlength="45"></td>
</tr>
<tr>
<td colspan="2"><p align="center">Enter your friend's email addresses:</p>
</td>
</tr>
<tr>
<td>Email 1*:</td>
<td><input name="fmail1" class="bordesolid1" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 2*:</td>
<td><input name="fmail2" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 3*:</td>
<td><input name="fmail3" size="30" maxlength="50"></td>
</tr>
<tr>
<td colspan="2"><p align="center"><span>This message will contain your name & email address.</span>
<br>
<input onClick="validate();" type="button" value="click once to send">
<input type=hidden name=refurl value="<? print $refurl;?>">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
PHP Code:
<?php
if(count($_POST)) {
foreach(array('fmail1','fmail2','fmail3','email','name') as $key) $_POST[$key] = strip_tags($_POST[$key]);
if(!is_secure($_POST)) {
die("Peace People! Stop Spamming!");
}
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$to = "arvindsri123#yahoo.com";
$subject = "Recommendation form submission";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">'.$name.' has used your recommendation form using an email address of '.$email.' </p>';
$message.='<p style="margin-top:10px;">The people the recommendation has been submitted to are: </p>';
$message.='<p style="margin-top:10px;">'.$fmail1.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail2.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail3.' </p>';
$message.='<p style="margin-top:10px;">The page recommended:</p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($to, $subject, $message, $headers);
// $thankyoupage = "thankyou.htm";
//echo $sentmail;
if($sentmail) {
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$tsubject = "A web page recommendation from $_POST[name]";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">Hi, '.$name.' whose email address is $_POST[email] thought you may be interested in this web page. '.$email.' </p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($fmail1,$fmail2,$fmail3, $tsubject $message, $headers);
echo '<h4>You have sent emails...</h4>';
//header("Location: $thankyoupage");
exit;
}
function is_secure($ar) {
$reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i";
if(!is_array($ar)) {
return preg_match($reg,$ar);
}
$incoming = array_values_recursive($ar);
foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false;
return true;
}
function array_values_recursive($array) {
$arrayValues = array();
foreach ($array as $key=>$value) {
if (is_scalar($value) || is_resource($value)) {
$arrayValues[] = $value;
$arrayValues[] = $key;
}
elseif (is_array($value)) {
$arrayValues[] = $key;
$arrayValues = array_merge($arrayValues, array_values_recursive($value));
}
}
return $arrayValues;
}
?>
I am using Bluehost web hosting, and other emails properly working as I said Contact us, Registration confirmation emails.. etc.
Thanks!
If you are running on localhost then it won't send email.. to do so you need to host on server
Try to host on free hosting server.. it will work!
Related
When i send some email, it only sends the first word from the subject:
Example: I send an email with the name of "Send email", it only sends the word "Send", how can i prevent that?
Code:
The subject is selected in a select box
<td><a>
<?= ' '.$val['email'].' '; ?>
<input type="text" value="<?= $val['email']; ?>" name="to"/>
</a></td>
<td>
<select name="subject">
<?php
foreach($templatesarr as $val){
echo '<option value='.$val['name'].'>'.$val['name'].'</option>';
}
echo '</select></td>
<td><input type="submit" name="send" value="Send e-mail" /></td>
</td></tr>
';
?>
</form>
Check if the button was clicked
if(isset($_POST['send'])){
$sendername = 'Company';
$from = 'noreplay#compaty.com';
$to = safe($_POST['to']);
$subject = safe($_POST['subject']);
$message = 'teste';
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= "From: $sendername <$from>".PHP_EOL;
mail($to, $subject, $message, $headers);
}else{
$to = NULL;
}
Safe function
function safe($value) {
return mysql_real_escape_string($value);
}
The main problem is caused by not escaping variables and not properly encapsulating your attribute values; use this instead:
foreach($templatesarr as $val){
printf('<option value="%1$s">%1$s</option>',
htmlspecialchars($val['name'], ENT_QUOTES, 'UTF-8')
);
}
It now uses "" to delimit the value attribute of the option element.
I have the following code:
<table class="table table-striped" id="itemsTable">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="item-row">
<td></td>
<td><input type="text" name="itemCode[]" value="" class="input-medium" id="itemCode"
tabindex="1"/>
</td>
<td><input type="text" name="itemDesc[]" value="" class="input-large" id="itemDesc"
readonly="readonly"/></td>
<td><input type="text" name="itemQty[]" value="" class="input-mini" id="itemQty" tabindex="2"/>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span>
<input
name="itemPrice[]"
class=" input-small"
id="itemPrice"
type="text"></div>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span><input
name="itemLineTotal[]" class=" input-small" id="itemLineTotal" type="text"
readonly="readonly"></div>
</td>
</tr>
</tbody>
</table>
What is the best way to process the inputs via php to send the order via email nicley formated into a table? This is an order form and I need to to simply be sent to an email once complete
Here is my processing code:
<?php
$to = $_REQUEST['xxx'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"itemCode"} = "Code";
$fields{"itemDesc"} = "Description";
$fields{"itemPrice"} = "Price";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: noreply#example.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
$send = mail($to, $subject, $body);
if($send){
header( "Location:index.php" );
} else {
print "We encountered an error sending your mail, please try again";
}
?>
This code is not working please help
To process a form this way you need to have a form element somewhere in your markup to process.
<form method="POST" action="yourSecondScript.php">
your first markup here
<input type="submit">
<form>
Then to make the email nice with tables you need to set the email headers to html.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_REQUEST['Name'] . ">\r\n";
mail($to, $subject, $body, $headers);
Where is
$to = $_REQUEST['xxx'] ;
coming from? My guess is that you can set it to fixed as you probably don't need a dynamic e-mail to address, so something like:
$to = 'myname#mydomain.com';
But as Michael mentioned in a reaction to your question, we cannot be sure until you tell us which part is not working / what errors you receive and so on..
I have been working on a php script and a html form (both in separate files) that takes data from a form and emails it to me. I am having difficulty getting the form data that the user fills out to come through on the email.
I would like for the email to contain the user's email as the From in the email.
Can anyone help me figure out what is wrong with the files?
HTML Form:
<form id="ContactUs" name="ContactUs" method="post" action="sendform/sendform.php">
<table width="60%" border="0" cellpadding="2px" style="position:relative; left:20%">
<tr>
<td width="25%" align="right">Name:</td>
<td width="75%" align="left"><input name="ContactName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td align="left"><span id="sprytextfield1">
<input name="EmailAddress" type="text" id="EmailAddress" size="40" maxlength="150" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Phone Number:</td>
<td align="left"><span id="sprytextfield2">
<label for="PhoneNumber"></label>
<input name="PhoneNumber" type="text" id="PhoneNumber" maxlength="15" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Practice Name:</td>
<td align="left"><input name="PracticeName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Message:</td>
<td align="left"><textarea name="Message" cols="40" rows="10"> </textarea></td>
</tr>
<tr>
<td align="center" width="25%"></td>
<td align="center" width="75%"><input name="SubmitForm" type="submit" id="SubmitForm" onclick="MM_popupMsg('Are you sure you would like to submit this form?\r');return document.MM_returnValue" value="Submit Form" /><input type="reset" name="ResetForm" id="ResetForm" value="Reset Form" /></td>
</table>
</form>
Separate PHP file named sendform.php
<?php
// Where to redirect after form is processed.
$url = 'ThankYou.php';
// multiple recipients
$to = 'T#domain.com';
// subject
$subject = 'Someone sent you a contact request';
$headers = 'From: '.$EmailAddress.'/r/n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charshet=ISO-8859-1\r\n';
// message
$messagetext = '<html><body>';
$messagetext .= ' <p>Website Form Submit</p>';
$messagetext .= ' <table>';
$messagetext .= ' <tr><td align="right">Name:</td><td>'; $_GET[$ContactName] .'</td></tr>';
$messagetext .= ' <tr><td align="right">Email Address:</td><td align="left">'; $EmailAddress .'</td></tr>';
$messagetext .= ' <tr><td align="right">Phone Number:</td><td align="left">'; $PhoneNumber .'</td></tr>';
$messagetext .= ' <tr><td align="right">Practice Name:</td><td align="left">'; $PracticeName .'</td></tr>';
$messagetext .= ' <tr><td align="right">Message:</td><td align="left">'; $Message .'</textarea></td></tr>';
$messagetext .= ' </table></body></html>';
// 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";
// Mail it
mail($to, $subject, $messagetext, $headers);
//echo $message;
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'
?>
You're using POST in your form but you are not referencing the post variables. Instead of $_GET[$ContactName], use $_POST[$ContactName]. Do this for all POSTed variables.
One step at a time! Forget the email function altogether for now, do things in order.
Make your form, then make sure it's displaying as you expect in the browser.
Then on the processing page (sendform/sendform.php), echo out all the data which would be sent from the form to make sure they're all there, present and ok.
ie
print_r($_POST);
THEN once you are happy with that stage, you can apply the vars in the email function and test the final result, tweaking where required or fixing bugs etc.
At present, however, you're not doing anything with the POSTed data. In sendform.php, you have this:
$headers = 'From: '.$EmailAddress.'/r/n';
However there is no reference to it in that file to set it, or set that variable to POSTed or GET data. As such, it'll be empty.
You should check your error logs too, as this would have shown you this var is empty and lead you to back track to your issue. error logs are a must whenever coding in PHP, even for the pro's.
You also have this:
$messagetext .= '<tr><td align="right">Name:</td>
<td>'; $_GET[$ContactName] .'</td></tr>
';
Your form is set to POST data, not GET.
So your data is stored in PHP's $_POST array. So using your form names, the email address would be:
$_POST['EmailAddress'];
// You can use this, or set it to a variable, ie
$EmailAddress = $_POST['EmailAddress'];
Important note:
You really want to validate people's inputs before emailing, or you could open yourself up to be a spammers delight. Such as strlen() to match your form maxlengths, is_numeric(), and regex to check their inputted data is not some Javascript or whatever trying to send thousands of emails through your site (it happens!).
Using them all in conjunction with each other where appropriate, you ensure users can only enter data you allow and you stop any bad things coming through.
Send them back to the form with an error message if there is anything wrong, do this until you're happy the data is acceptable to send through your server's mail system and then allow it.
People using your badly written code to spam the world wont just be an annoyance to you having to resolve that. You could end up having your domain name where the form is hosted blacklisted as a spammy site - not good.
Here is a tested version with the From: now showing in the appropriate location of the Email.
Quick note: There was two seperate header bodies which broke up your code.
One under $subject and the other over $messagetext. All are inside one body of headers now.
Plus, you had $headers = 'From: '.$EmailAddress.'/r/n'; which is invalid.
This should have read as $headers = 'From: '.$EmailAddress.'\r\n'; with \ instead of /.
More on the mail() function can be read by visiting PHP.net on mail() - here.
Working code
<?php
$url = 'ThankYou.php';
$ContactName = $_POST['ContactName'];
$EmailAddress = $_POST['EmailAddress'];
$PhoneNumber = $_POST['PhoneNumber'];
$Message = $_POST['Message'];
$PracticeName = $_POST['PracticeName'];
$to = "email#example.com";
$subject = 'Someone sent you a contact request';
// message
$messagetext = '<html><body>';
$messagetext .= ' <p>Website Form Submit</p>';
$messagetext .= ' <table>';
$messagetext .= ' <tr><td align="right">Name:</td><td>'.$ContactName.'</td></tr>';
$messagetext .= ' <tr><td align="right">Email Address:</td><td align="left">'.$EmailAddress.'</td></tr>';
$messagetext .= ' <tr><td align="right">Phone Number:</td><td align="left">'.$PhoneNumber.'</td></tr>';
$messagetext .= ' <tr><td align="right">Practice Name:</td><td align="left">'.$PracticeName.'</td></tr>';
$messagetext .= ' <tr><td align="right">Message:</td><td align="left">'.$Message.'</textarea></td></tr>';
$messagetext .= ' </table></body></html>';
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: $EmailAddress" . "\r\n" .
"Reply-To: $EmailAddress" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Mail it
mail($to, $subject, $messagetext, $headers);
//echo $message;
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
//echo "Success"; // my testing method
?>
Additional options:
To make sure someone fills in all the fields and not send mail unless they do, then you can use the following and make sure you remove the in your <textarea name="Message"... because that is considered as input.
if(!empty($_POST['EmailAddress']) && (!empty($_POST['ContactName']))
&& (!empty($_POST['PhoneNumber']))
&& (!empty($_POST['PracticeName']))
&& (!empty($_POST['Message']))
)
{
mail($to, $subject, $messagetext, $headers);
//echo $message;
// echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
echo "Success";
}
else {
echo "Mail failed. All fields must be filled.";
}
There are more improvements that can be done, for instance Email validation such as FILTER_VALIDATE_EMAIL.
Example:
$email = $_POST['EmailAddress'];
if(empty($_POST['EmailAddress']) || !filter_var($EmailAddress, FILTER_VALIDATE_EMAIL)) {
die("Please enter a valid email");
}
More on FILTER_VALIDATE_EMAIL can be found on the PHP.net Website
http://php.net/manual/en/filter.filters.validate.php
I have fixed your code. Enter the email in $to variable whom you want to send the email.
<?php
$ContactName = $_POST['ContactName'];
$EmailAddress = $_POST['EmailAddress'];
$PhoneNumber = $_POST['PhoneNumber'];
$Message = $_POST['Message'];
$PracticeName = $_POST['PracticeName'];
$to = 'ENTER EMAIL ADDRESS ON WHICH YOU WANT TO SEND EMAIL';
$subject = 'Someone sent you a contact request';
$headers = 'From: '.$EmailAddress.'/r/n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charshet=ISO-8859-1\r\n';
// message
$messagetext = '<html><body>';
$messagetext .= ' <p>Website Form Submit</p>';
$messagetext .= ' <table>';
$messagetext .= ' <tr><td align="right">Name:</td><td>'.$ContactName.'</td></tr>';
$messagetext .= ' <tr><td align="right">Email Address:</td><td align="left">'.$EmailAddress.'</td></tr>';
$messagetext .= ' <tr><td align="right">Phone Number:</td><td align="left">'.$PhoneNumber.'</td></tr>';
$messagetext .= ' <tr><td align="right">Practice Name:</td><td align="left">'.$PracticeName.'</td></tr>';
$messagetext .= ' <tr><td align="right">Message:</td><td align="left">'.$Message.'</textarea></td></tr>';
$messagetext .= ' </table></body></html>';
// 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";
// Mail it
mail($to, $subject, $messagetext, $headers);
//echo $message;
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
I have made a form for registration by php .The form has submitter email address field.I want that after form submission , form content will send to both form submitter and admin via submitter email address and admin email address. Submitter email address will get from submitter email address field.Admin email address is fixed .
For Submitter
headers= "from : no-reply#eschool.com"
messagebody same as it is
For admin
headers=" from :$email"
messagebody same as it is
I tried to do this:
Html code:
<form action="action.php" method="post">
<table>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="name" width="400" /></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input type="text" name="address" width="400" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email" width="400" /></td>
</tr>
<tr>
<td>Password</td>
<td rowspan="2"> </td>
<td>
<p><input type="text" name="pass" width="400" /></p>
<p> </p>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="insert" value="Insert" /></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
action.php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$to = $email . "," . $admin;
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply#eschool.com ". "\n";
mail($to, $subject, $email_message, $headers);
Thanks
Your code is perfect, what is your are facing problem, plz write your problem.
Make following change in action.php for your convenience :
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
//$to = $email $admin;
$email_message = '';
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers1 .= "From: no-reply#eschool.com ". "\n";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers2 .= "From: ". $email . "\n";
if(#mail( $email, $subject, $email_message , $headers1 )) {
#mail( $admin, $subject, $email_message , $headers2 )
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
You can simply make two different versions of your headers and execute mail(...) twice:
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$email_message = "Name: ".$name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type:text/plain;charset=UTF-8;\n";
$headers .= "content-Transfer-encoding: 8bit\n";
$poster_headers = $headers . "From: no-reply#eschool.com\n";
$admin_headers = $headers . "From: ".$email."\n";
mail( $admin, $subject, $email_message, $admin_headers );
mail( $email, $subject, $email_message, $poster_headers );
?>
I'm trying to send a small batch of emails in a loop using PHP mail(). The script to send the emails works fine. There is, however, a slight glitch. Whilst the recipients all receive only one email, the first person on the list receives the email body ($MESSAGE_BODY) once, the second person gets the body twice and the third person gets it 3 times (and on it goes). I cannot for the life of me work out why it's doing it.
The form from which the emails are sent is:
<p>Message Text:
<br />
<textarea name="thebody" id="thebody" cols="65" rows="12"><?php echo $row_email['emailtext'];?></textarea>
<script type="text/javascript">CKEDITOR.replace( 'thebody' );</script>
</p>
<table >
<tr>
<th>Site</th>
<th>Email Address</th>
<th colspan="2">Email Now?</th>
</tr>
<?php
$b = 0;
$q = 1;
while ($row_selfdo = mysql_fetch_assoc($selfdo)) { ?>
<tr>
<td><?php echo $row_seldo[‘sitename’];?></td>
<td><input type="text" name="emailto[]" style="font-size:9px;" size="20" value="<?php echo $row_selfdo['eaddress']; ?>"/></td>
<td valign="middle">Yes:<input type="radio" name="emailnow[<?php echo $b;?>]" value="Yes" <?php if (isset($mailed) && ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?> /></td>
<td>No:<input name="emailnow[<?php echo $b;?>]" type="radio" value="No" checked="checked" <?php if (isset($mailed) && ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?>? /></td>
</tr>
<?php $b++; $q++; } ?>
</table>
And here's the script to send the mail
$numb = count($_POST['emailto']);
$num = $numb -1;
$subject=$_POST['subject'];
$thisrecipient = $_POST['emailto'];
$sendtothemnow = $_POST['emailnow'];
for ($a=0;$a<=$num;$a++) {
$emailthemnow = $sendtothemnow[$a];
if ((isset($emailthemnow))&&(($emailthemnow)=="Yes")) {
$recipient = $thisrecipient[$a];
$ToEmail = $recipient;
$EmailSubject = $subject;
$mailheader = 'From: me#mydomain.com'."\r\n";
$mailheader .= 'Reply-To: me#mydomain.com'."\r\n";
$mailheader .= 'MIME-Version: 1.0'."\r\n";
$mailheader .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$MESSAGE_BODY .= '<p>'.$_POST['thebody'].'</p>';
$MESSAGE_BODY .= '<p>Kind Regards</p>';
$MESSAGE_BODY .= '<p>The Environment Team</p>';
$MESSAGE_BODY .= 'email footer bits here ';
$MESSAGE_BODY .='<p style="color:#0C0;">Please consider the environment - do you really need to print this email?';
$MESSAGE_BODY=wordwrap($MESSAGE_BODY,70);
$mailsent= mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Not Sent");
if($mailsent){
//update a table to record date email was sent
}
}//end email send loop
Any suggestions??
Many thanks in advance
On your first line where you use the message body, set it instead of appending it:
$MESSAGE_BODY = '<p>'.$_POST['thebody'].'</p>';
(The dot has been removed)
Only change the variable name which have conflict.
if ((isset($emailthemnow))&&(($emailthemnow)=="Yes")) {
$recipient = $thisrecipient[$a];
$ToEmail = $recipient;
$EmailSubject = $subject;
$mailheader = 'From: me#mydomain.com'."\r\n";
$mailheader .= 'Reply-To: me#mydomain.com'."\r\n";
$mailheader .= 'MIME-Version: 1.0'."\r\n";
$mailheader .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$MESSAGE_BODY .= '<p>'.$_POST['thebody'].'</p>';
$MESSAGE_BODY .= '<p>Kind Regards</p>';
$MESSAGE_BODY .= '<p>The Environment Team</p>';
$MESSAGE_BODY .= 'email footer bits here ';
$MESSAGE_BODY .='<p style="color:#0C0;">Please consider the environment - do you really need to print this email?';
$MESSAGE_BODY_FINAL=wordwrap($MESSAGE_BODY,70);
$mailsent= mail($ToEmail, $EmailSubject, $MESSAGE_BODY_FINAL, $mailheader) or die ("Not Sent");
if($mailsent){
//update a table to record date email was sent
}
}