473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP form submit but no email

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 
  2.  
  3.     $to           = "tenders@example.com";
  4.     $subject      = "Enquiry form submitted " . date("F j, Y, g:i a");
  5.  
  6.     $fromaddress = "enquiryform@example.com";     
  7.  
  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
11 2970
Atli
5,058 Expert 4TB
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
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
Atli
5,058 Expert 4TB
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
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
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
No, we do not have a database, we just use the form for potential clients to send us requests.
Apr 12 '10 #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.
Suggestions??

here is the snippet...
Expand|Select|Wrap|Line Numbers
  1. // Email Layout
  2.  
  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>';
  10.  
  11.  
  12.  
  13.  
  14.  // Send the mail 
  15.  
  16. $Name = "Mike Lomman"; //senders name
  17. $email = "mikelomman@hotmail.com"; //senders e-mail address
  18. $recipient = "tenders@russco.com.au"; //recipient
  19. $mail_body= $message ;//mail body
  20. $subject = "Test Test Test"; //subject
  21. $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
  22.  
  23. ini_set("sendmail_from", "enquiryform@russco.com.au"); //Suggested by "Some Guy"
  24.  
  25.  
  26. //$header  = 'MIME-Version: 1.0' . "\r\n";
  27. //$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  28. //$header.='Reply-To: tenders@russco.com.au'  . "\r\n" . 'X-Mailer: PHP/' . phpversion();
  29.  
  30.  
  31.  
  32. mail($recipient, $subject, $mail_body, $header); //mail command :)
  33.  
  34.  
Apr 16 '10 #8
Atli
5,058 Expert 4TB
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.

P.S.
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
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
Atli
5,058 Expert 4TB
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
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

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

Similar topics

5
by: Marc | last post by:
Hello, I have a self - submitting form with multiple submits and I want to detect after the submit which button is pressed. Code example: <form name="example" method="post"...
12
by: Roger Price | last post by:
Thank you to Yang (Is that your first name?) and Andy for your suggestions. I am 99% of the way there but now cannot get the "Reset" button to work. I have included the whole of my code and...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
1
by: Sithlord999 | last post by:
Hello. I'm working on an email form on Dreamweaver and I'm looking for a PHP code to make it work. The form with some required fields would send the submitted information and two image attachments...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
6
by: Spycat | last post by:
Hi all and happy holidays! I should start off by stating I am NOT a PHP programmer. I say that so that in any response to me, you will speak very s-l-o-w-l-y or I won't know what you're talking...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
5
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but...
12
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.