PHP Contact Form

jakeselectronics

New Member
Messages
38
Reaction score
0
Points
0
I had a working Contact form and now it has parcially stopped working.

I have the form on my site, and what it would do is send me an email, as well as the person who sent it. Like an auto reply confirmation email to them.

I have been sitting here all day trying to figure out whats wrong and I still am not sure.

I have norrowed it down though.
When i take the '$from' bit out of this: $send = mail($to, $subject, $body, $from);
It works.

But the email ends up in my junk folder. without a from address. Which is annoying because i cant just hit reply.
and when its included ( '$from' ), i dont get an email at all.

here's the whole .php code:
Can anyone see anything obvioulsy wrong.
PHP:
<?php
if (isset($_POST['submit'])){
 
 $name = $_POST['name'];
 $email = $_POST['email'];
 $subjectabout = $_POST['subject']; 
 $mailinglist = $_POST['list'];
 $message = $_POST['message'];
 
 $to = "jephpform@hotmail.com";
 $subject = "JE - Result From Web Form";
 $from = "From: $name <$email>"; 
 
 $body = "Name: $name\nE-Mail: $email\nSubject: $subjectabout\nAdd to Mailing list: $mailinglist\nMessage:\n\n       $message";
 
 $autoreplymessage = "Thanks $name for contacting me.\nI will get back to you as soon as possible.\n\n\nThe following information was sent:\n$body";
 $autoreplysubject = "Thank you for contacting Jake"; 
 $autoreplyheader = "From: NoReply - Jake's Electronics <noreply@jakeselectronics.com>"; 
 
if($name == '') 
{header( "Location: http://jakeselectronics.x10hosting.com/con-incomplete.php" );}  
else { 
if($email == '') 
{header( "Location: http://jakeselectronics.x10hosting.com/con-incomplete.php" );}  
else {
if($message == '') 
{header( "Location: http://jakeselectronics.x10hosting.com/con-incomplete.php" );}  
else { 
$send = mail($to, $subject, $body, $from);           // This sends an email to me
$send2 = mail($email, $autoreplysubject, $autoreplymessage, $autoreplyheader);  // This sends an email to them
if($send) 
{header( "Location: http://jakeselectronics.x10hosting.com/con-thanks.php" );} 
else 
{header( "Location: http://jakeselectronics.x10hosting.com/con-error.php" );} 
}
}
}
}
?>

And here's my webpage for the contact form..
http://jakeselectronics.x10hosting.com/contact.php
 

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
Pls include validation , i will check ur code and post the reply as soon as possible.
 

jakeselectronics

New Member
Messages
38
Reaction score
0
Points
0
Someone just sent an email using the current contact form

heres a picture of what i got.
1,2 and 3 are what I just received.
picture 4 is the way it used to work. (ignore the different receive address)

The different between them is that the persons email address doesn't show up anymore.
This is why it ends up in the junk folder, plus i cant press 'reply'.

notice in picture 4, the name and the email of the person using the form would come through.

62d978312b.jpg


is there anything wrong with this:?
PHP:
$from = "From: $name <$email>";

Because when i add this: nothing comes through at all.
PHP:
mail($to, $subject, $body, $from);

This is how it is for the email i received in the picture above:
PHP:
mail($to, $subject, $body);
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
In the past, users have reported that PHP mail has stopped going out if the "From" header was from a third party...hotmail, gmail, etc, even though it worked for awhile.

By setting the "From" header to an address from your website, the mail started going out again. I do not remember anybody saying posting back later saying it stopped.

Maybe the mail server is set up to monitor outgoing to make sure that accounts are not used for "phishing" and stop sending emails that have questionable (ie not attached to the account) "From" headers. Admin has never commented on this.
 

jakeselectronics

New Member
Messages
38
Reaction score
0
Points
0
So there's not too much wrong with the code.
Well I guess it worked before...

So if i was to change servers/hosts, it may possibly start working properly again?
 

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
I checked it and it was working.. If you want i will mail you another contact form.PM me ur mail id
 

marley17

New Member
Messages
58
Reaction score
1
Points
0
for alternatives,,, you could try a free service of jotform... the site is http://www.jotform.com

its a web based form creator, i do have three accounts on there because they only allow 100 messages per month on a free account.so when the one expires i use the other account.. hehe. i found it useful since in reality people use the contact form not too often ... whats great is .. less bandwidth usage, more secure... and you are confident that messages are send right away..
 
Last edited:

xgreenberetx

New Member
Messages
57
Reaction score
1
Points
0
Code:
    $to = $email;
    $subject = 'Your Registration';
    $message = '<html><body>
    Please follow these instructions to verify your registration:<BR>
Instructions bla bla' ;
    $headers .= "From:$email \r\n";
    $headers .= "Reply-To: <"$email">\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($to, $subject, $message, $headers)

Try using the header option instead, and see if that works out.
 

jakeselectronics

New Member
Messages
38
Reaction score
0
Points
0
Thanks for your help xgreenberetx

but i got an error with this line
PHP:
   $headers .= "Reply-To: <"$email">\r\n";

this is what the error said:
Parse error: syntax error, unexpected T_VARIABLE in /home/jakesele/public_html/sendmail.php on line 15
Edit:
Problem solved!

There's nothing wrong with the coding.

I switched Webhosts and walla! it works perfectly!

Thanks for all your help though everyone.

Now, who wants all my credits?

haha just kidding :D
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
but i got an error with this line
PHP:
   $headers .= "Reply-To: <"$email">\r\n";
The line is missing string concatenation operators or has extra double-quotes (depending on how you want to view it).
PHP:
   $headers .= "Reply-To: <" . $email. ">\r\n";
// OR
   $headers .= "Reply-To: <$email>\r\n";
 
Top