...

View Full Version : Email form not sending



Simon R
02-19-2010, 09:22 AM
Hello All!

Im new here and to php! Im having a few problems with a email form, i can get this to send


<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

But not this -


<?php
mail('sales@vandiscount.co.uk','Test mail','The mail function is working!');
echo 'Mail sent!';
?>

This one gives me the error -

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\nas01\nas\v\a\vandiscount.co.uk\web\mailtest.php on line 2
Mail sent!

Then if i try this in my code it send but i receive nothing -


<?php
if(isset($_POST['submit'])) {

$to = "sales@vandiscount.co.uk";
$subject = "Form Submission";
$name_field = $_POST['firstname1'];
$email_field = $_POST['companyname1'];
$number_field = $_POST['lastname1'];
$time_field = $_POST['mobile1'];
$comments_field = $_POST['phone1'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "message sent!";

}
?>

and heres what im actaully using as the mailform page, sorry for the large amount but its driving me insane! -


<tr>

<td bgcolor="#C0C0C0" width="148"><b>
<font face="Arial">Contact us below</font></b><p align="center"><b>
<font face="Arial" size="2">(Use the TAB Key to move down the form)</font></b></td>
</tr>
<tr>
<td width="148" height="55">
<b><font face="Arial" size="2">Your name</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:24" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="firstname1" size="20"></font></td></tr>
<tr>
<td height="50" width="148">
<b><font face="Arial" size="2">Your number</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:25" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="lastname1" size="20"></font></td></tr>
<tr>
<td width="148" height="50">
<b><font face="Arial" size="2">Your email</font></b><font face="Arial"><input style="width: 143;height:25" type="text" value="" name="companyname1" size="20"></font></td></tr>
<tr>
<td width="148">
<b><font face="Arial" size="2">Your requirements</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:132" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="phone1" size="20"></font></td></tr>
<tr>
<td width="148" height="52"><b><font face="Arial" size="2">Preferred time to
contact you</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:22" type="text" value="" name="mobile1" size="20"></font></td></tr>
<tr>
<td align="center" width="148"><font face="Arial, Arial, Helvetica">
<input class="sendbutton" type="submit" value=" Submit Form " name="submit_apply1"> </font></td></tr></tbody></table>

Simon R
02-19-2010, 09:22 AM
Thanks for any help at all guys, im very new to this but im a fast learner,

Simon

DaiWelsh
02-19-2010, 09:42 AM
As the error message suggests your server requires a From: header to be set (most servers don't like 'anonymous' mail, though some will substitute a default from address).

In your first example you are using the fourth parameter to the mail() call which is the additional headers parameter and passing it "From: $from" so it has a from address, in the second example you are not using the fourth parameter at all and hence not giving a from address.

HTH,

Dai

[Paul Ferrie ]
02-19-2010, 10:00 AM
Just to reinforce what DaiWelsh said. I have a few flash+php mail forms (http://www.scotflash.co.uk/blog/?s=contact) on my blog that use headers in the mail function().

I typical code would look like:


$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: your@email.com\r\n";
$headers .= "Reply-To: your@email.com\r\n";

mail($to, "Some subject", $msg, $headers);


hope it helps

Simon R
02-19-2010, 01:15 PM
Thanks for the help guys :)

Going to give this below a try when home -


<?php
if(isset($_POST['submit'])) {

$to = "sales@vandiscount.co.uk";
$from = "admin@vandiscount.co.uk";
$subject = "Form Submission";
$name_field = $_POST['firstname1'];
$email_field = $_POST['companyname1'];
$number_field = $_POST['lastname1'];
$time_field = $_POST['mobile1'];
$comments_field = $_POST['phone1'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "message sent!";

}
?>

DaiWelsh
02-19-2010, 01:38 PM
No that won't work you need to use the fourth parameter for headers e.g.



<?php
$headers = "From: $from\nReply-To: $from\n";
mail($to, $subject, $body,$headers);
?>


Anything you pass in the third param will be part of the message body, headers (other than the default ones that get set by mail()) need to go in the fourth param (see docs).

Regards,

Dai

Fou-Lu
02-19-2010, 03:47 PM
<?php
if(isset($_POST['submit'])) {

$to = "sales@vandiscount.co.uk";
$subject = "Form Submission";
$name_field = $_POST['firstname1'];
$email_field = $_POST['companyname1'];
$number_field = $_POST['lastname1'];
$time_field = $_POST['mobile1'];
$comments_field = $_POST['phone1'];

$body = 'Body here, just a test';
$headers = "From: $from\r\nReply-To: $from\r\n";

if (mail($to, $subject, $body, $headers))
{
echo "Data has been submitted to $to!";
}
else
{
echo 'Unable to send mail';
}
}
?>


If running the above produces output that mail was submitted, php is happy. If you're not receiving you're email, ensure that an smtp server has been configured in you're php.ini or pass it in as an argument to the 5th parameter. If you're locally served, ensure that you have an smtp service installed and configure it in you're php.ini file. If you're hosted, contact you're hosting company to ask what the sendmail path should be.

Simon R
02-19-2010, 08:46 PM
<?php
if(isset($_POST['submit'])) {

$to = "sales@vandiscount.co.uk";
$subject = "Form Submission";
$name_field = $_POST['firstname1'];
$email_field = $_POST['companyname1'];
$number_field = $_POST['lastname1'];
$time_field = $_POST['mobile1'];
$comments_field = $_POST['phone1'];

$body = 'Body here, just a test';
$headers = "From: $from\r\nReply-To: $from\r\n";

if (mail($to, $subject, $body, $headers))
{
echo "Data has been submitted to $to!";
}
else
{
echo 'Unable to send mail';
}
}
?>


If running the above produces output that mail was submitted, php is happy. If you're not receiving you're email, ensure that an smtp server has been configured in you're php.ini or pass it in as an argument to the 5th parameter. If you're locally served, ensure that you have an smtp service installed and configure it in you're php.ini file. If you're hosted, contact you're hosting company to ask what the sendmail path should be.


Just tried this and i dont receive any mail, ive opened a ticket with namesco to ask what the sendmail path should be. Ive also requested to move from windows hosting to linux.

Simon R
02-20-2010, 11:11 AM
Ok ive manage to get one of the fields working but non of the others and heres how ive got to that -


<?php
$to = "sales@vandiscount.co.uk";
$subject = "Online Mail Form";
$from = "admin@vandiscount.co.uk";
$headers = "From: $from";
$name_field = $_POST['firstname1'];
$email_field = $_POST['companyname1'];
$number_field = $_POST['lastname1'];
$time_field = $_POST['mobile1'];
$comments_field = $_POST['phone1'];
mail($to,$subject,$comments_field,$headers);
echo "Mail Sent.";
?>

But in the 10thline i cant add more than 5 parameters can i? how can i add the others in?

Simon R
02-20-2010, 11:20 AM
The errors i get if i add any other _field in is -

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\nas01\nas\v\a\vandiscount.co.uk\web\thanks.php on line 20
Mail Sent.

[Paul Ferrie ]
02-20-2010, 12:31 PM
You have already been shown how the header should be formed.


$headers = "From: $from\r\nReply-To: $from\r\n";

Most probably the missing field is replyTo



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum