By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

PHP form submit but no email

P: 7
Thank you for your patience. I have looked at numerous forums to no avail.
I have a simple form html/php, for visitors to send questions.
The form is on page 1, which submits to page to, echoes the form and then redirects to index.php. The form picks up the data, and posts it on page 2 , but no email arrives in the inbox nor junk box. I whittled everything on page 2 back to

Expand|Select|Wrap|Line Numbers
  1.  // Send the mail 
  3.     $to           = "";
  4.     $subject      = "Enquiry form submitted " . date("F j, Y, g:i a");
  6.     $fromaddress = "";     
  8.      mail($to, $subject, $message);
, with still no luck. I have asked my web host but they refuse to assist. Can the problem be within the php.ini file??

The form sends the data from page 1 to page 2 where it is echoed, but nothing arrives in the mail box and no error messages appear.

Many Thanks in advance
Apr 8 '10 #1
Share this Question
Share on Google+
11 Replies

Expert 5K+
P: 5,058
Do you have the error messages turned on?

My first guess would be that this is because you do not specify the From header. It needs to be specified for the mail function to work, either in the PHP config or using it's fourth parameter.

See the second example in the manual entry for the mail function. Try to add something similar to your code and see if that works.
Apr 8 '10 #2

P: 7
Atli, yes thanks, I have tried that, no difference.
My gut feeling is that the php.ini file is stopping the send mail, and I can't edit this, nor get the webhost to edit it either.
Apr 9 '10 #3

Expert 5K+
P: 5,058
Ok. If you have no power to alter the config, and the mail function doesn't seem to be configured properly, you could try to use one of the mailer classes. Both PHPMailer and Swift Mailer have worked well for me in the past.

With them, even if your server does not provide a sendmail or SMTP server, you can have them use an external program. They can even be made to use the Gmail SMTP server. (Be careful though. Gmail is not meant for mass-mailing.)
Apr 9 '10 #4

P: 7
Thanks Atli, I tried both of those, obviously didn't do it right coz neither of them worked. I think fu*k it, people can ring us, the numbers on the page.
Apr 9 '10 #5

P: 96
hey man...

i know this may seem too simple but the problem is usually obvious...

do you have a database program like... wamp...
Apr 9 '10 #6

P: 7
No, we do not have a database, we just use the form for potential clients to send us requests.
Apr 12 '10 #7

P: 7
After further deliberation I find that my form can send to another email address but with no senders address, just 'anonymous' which is why the server blocked it. However, no matter what I try I cannot get the senders email address to show up AND have the email html formatted at the same time.

here is the snippet...
Expand|Select|Wrap|Line Numbers
  1. // Email Layout
  3.     $message='<html>';
  4.     $message.='<head>';
  5.     $message.='<title>Enquiry form</title>';
  6.     $message.='</head>';
  7.     $message.='<body>';
  8.     $message.=$messagebody ;
  9.     $message.='</body></html>';
  14.  // Send the mail 
  16. $Name = "Mike Lomman"; //senders name
  17. $email = ""; //senders e-mail address
  18. $recipient = ""; //recipient
  19. $mail_body= $message ;//mail body
  20. $subject = "Test Test Test"; //subject
  21. $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
  23. ini_set("sendmail_from", ""); //Suggested by "Some Guy"
  26. //$header  = 'MIME-Version: 1.0' . "\r\n";
  27. //$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  28. //$header.='Reply-To:'  . "\r\n" . 'X-Mailer: PHP/' . phpversion();
  32. mail($recipient, $subject, $mail_body, $header); //mail command :)
Apr 16 '10 #8

Expert 5K+
P: 5,058
In that code, all you should need to do is uncomment the content-type and mime-version headers, to have the message sent as HTML. - Make sure you add the period before the = on line #26, or it will overwrite the From header, rather than add to it.

You don't need to set the sendmail_from directive (line #23) if you supply the From header in the mail function itself.
Apr 16 '10 #9

P: 7
Thanks again Atli,
I still can not get the form to send an email to my work primary email address. It will however send to my secondary gmail and hotmail accounts, with the html formatted correctly and a senders name and email showing. I can even get it to send with my work email address as the senders address and still nothing. I feel that maybe there is some anti spam on the server stopping it coming through.
Apr 20 '10 #10

Expert 5K+
P: 5,058
Yea. If the email is getting through to one of your accounts but not another, the code is not to blame. There is most likely an anti-spam feature blocking it.
Apr 20 '10 #11

P: 7
Update on my form concern.
I have moved the page, "thanks for your submission" to another server and this now works as advertised. I guess that there was an issue with the spam settings, something that the provider refused to look into.
Now all I need is to validate the input and secure the input from spammers.
Thanks for all your efforts in assistance.
May 7 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.