Can't reply to email received from my contact page.

Hi everyone. I am Hadi and just joined here. First off, I have no knowledge of php. I created my webpage as school project. The contact page was created by a project member who was familiar with php. The semester is over and I am attempting to go live. As it turns out, I can receive contact info from my site to my email inbox but unable to reply to the site visitor. The php file starts with:

<?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_email = $_POST['cf_phone']; $field_message = $_POST['cf_message']; I receive the phone number as email address (that is what the 3rd line of code is set to do) and I suspect that is why I can not reply. I don't know why it is programmed this way. I changed line 3 to $field_phone = $_POST['cf_phone']; I won't even receive an email from contact page. I switched places of line 2 and 3. Won't even receive an email. If I change anything in these 4 lines, I won't even receive an email from the contact page. If I repeat line 2 after line 3, I won't even receive an email from the contact page. Code files are attached. Please note that the problem is that I receive phone number as visitors email address and therefore I can not Reply to the site visitor. Thank you all in advance. --- phphelpDocs.zip (1.37 KB)

Please post all the relevant code here, including what you already have + the actual sending of the email + the form.

You are right in there being some problems with the supplied code. The second “$field_email =” will overwrite the previous one.

Hi JimL, I did attach a zip file containing the php code and the form section of the html. Please let me know if you can not see it.

JimL gave you the answer. Your email address is being over-written with your phone number…

Well, I tried to send the entire zipped directory of all relevant files but it was rejected for being too large.

I had already attached html and php codes to my first post. Here I am attaching a sample contact data received in my in box and a sample of delivery failure info when I try to Reply to site visitor. Hope these help.

Thanks
Hadi


phpHelp2.zip (1.06 KB)

Hi Ernie, Please read my first post. I don’t know php and already suspected the email override. The problem is if I in any way modify lines 2 or 3, I won’t even receive any mail in my inbox from the site. That is why I am seeking help here.

Thanks

Common sense says to modify this line,

[php]$field_email = $_POST[‘cf_phone’]; [/php]
To
[php]$field_phone = $_POST[‘cf_phone’]; [/php]

I don’t really know how else to explain the problem and what I have done other than the way I wrote it in my first post. I just googled the code and it appears that this contact code had been picked up from the internet by my project partner. (I thought he wrote it!). I see other people having problem with this same code but I haven’t found one that found a solution for it. I will continue searching.
Thanks for the suggestion anyway.

I used echo statements to see how the data flows

If I keep the code as below using echo shows the expected. In this case I receive the contact data in my inbox with email replaced by phone number: As a result I can not reply to the message.

<?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_email = $_POST['cf_phone']; $field_message = $_POST['cf_message']; I changed the code to: <?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_phone = $_POST['cf_phone']; $field_message = $_POST['cf_message']; I echoed every line containing the inputted data in the php file. The data is echoed correctly all the way to the end (emai = email address, phone = phone#, etc..) but I won't receive an email in my inbox at all. So there is more into the "$field_phone = $_POST['cf_phone'];" line than what is obvious but I don't know what!

Well, there were a lot of extra slashes ( “/” ) in your code and one extra brace ( “}” ), but, it looks like it should work
with these fixed. Not sure of the FROM in the headers. It depends on your email address. You must replace the
"[email protected]" with your own email address. Normally, the FROM in the headers is an email address on
your server.

[php]

<?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_phone = $_POST['cf_phone']; $field_message = $_POST['cf_message']; $mail_to = '[email protected]'; $subject = 'Message from a site visitor '.$field_name; $body_message = 'From: ' . $field_name . "\n"; $body_message .= 'E-mail: ' . $field_email . "\n"; $body_message .= 'Message: ' . $field_message; $headers = 'From: ' . $field_email . "\r\n"; $headers .= 'Reply-To: ' . $field_email . "\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <?php } else { ?> <?php } ?>

[/php]
Also, the "[email protected]" in the last part is from the template your partner downloaded. changed it…

Thanks Ernie. Yes of course I put a valid email for “From”. I am using a 2nd email of my own as visitor email for testing. I also replaced [email protected] at the end of the code to my own email. In either case, no pop up appears to alert me to send an email when the visitor data fails to go through. I talked to my Host, they ran a mail test script on my contact page and it passes for them. They sent the link to me and I verified it too. What still drives me crazy is:
With $field_email = $_POST[‘cf_phone’]; I receive visitor data in my inbox though visitor email is the phone#.
With $field_phone = $_POST[‘cf_phone’]; it somehow disables the Mail_to which is the recipient’s mail and therefore no mail is received.

Well, actually, the PHP mail() function does not return anything except true/false. It is not very good if you need
to verify that it worked. Did you try my version I posted? Perhaps there is a spelling issue in your version?

Also, remember that if the email that is being sent to is from AOL, Yahoo, Gmail or other systems that use DMARC,
you can not use their email as the FROM address. You would need to use an email account on your server for
the FROM address and the REPLY-TO can be any email address.

If you need to use a more robust mailing function, most everyone on this site suggests using PHPmailer. It is a
free library that has more email functions than you will ever use. It also has a solid error-checking so you can
tell if the mail was sent out correctly.

I will take your form and code I posted and put it up on my server later one to test it live for you…

Hadia,
I tested my version of your code on my server. It works correctly and it sends out the email as it should.
Not sure why it does not work for you. Here is a copy of the two files for my version. I removed a lot of your
formatting as it is just wasted code. (DIV’s are not needed in a form unless you plan to use it later to fancy up
the displays.) I just wanted to make sure this version works and it does!

contact.html
[php]

Full Name
 <label   for="cf_email">Email</label> 
 <input id="Field3" name="cf_email" type="email" spellcheck="false" value="" maxlength="255" tabindex="3">     

 <label   for="cf_phone">Phone</label>
 <input id="Field5" name="cf_phone" type="text" spellcheck="false" value="" maxlength="255" tabindex="5"> 

 <label  for="cf_message">Message</label>
 <textarea id="Field4" name="cf_message" spellcheck="true" rows="10" cols="50" tabindex="4"></textarea>

 <input id="saveForm" name="saveForm" type="submit" value="Send">
[/php]

contact.php
[php]

<?php $field_name = $_POST['cf_name']; $field_email = $_POST['cf_email']; $field_phone = $_POST['cf_phone']; $field_message = $_POST['cf_message']; $mail_to = 'ErnieAlex@???.com'; // Change this to YOUR email address... $subject = 'Message from a site visitor '.$field_name; $body_message = 'From: ' . $field_name . "\n"; $body_message .= 'E-mail: ' . $field_email . "\n"; $body_message .= 'Message: ' . $field_message; $headers = 'From: ' . $field_email . "\r\n"; $headers .= 'Reply-To: ' . $field_email . "\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <?php } else { ?> <?php } ?>

[/php]

Ernie, I really appreciate your help and I have no doubt that this code worked for you because the line $mail_status = mail($mail_to, $subject, $body_message, $headers);
echos the correct data including the recipient and senders emails.
Unfortunately, I ran it and did not work for me. still receiving no email. In a few days I am going to have someone take a look at it directly on my computer and my site. If I find anything I will update this page.
In the meantime, I have a feeling that I have to look for an alternative for my contact page.

Thank you and all others who helped.
Hadi

Well, hopefully you will find the issue. I do know that some sites do not allow emailing from the server.
You can usually tell by looking at the PHP list and look for the mail functions. You do that by just adding this
line on a blank page: phpinfo(); Just make a page like this:

<?PHP phpinfo(); ?>

And, go to the page on your server and look down the list. It might be the site does not allow emailing.
(This is not common, but, I have another site that does not allow emails, so I had to post the email to another
server and have it send the email for the client. Which works.)

Good luck!

Have you checked your spam box for the emails? Just because they don’t hit your inbox doesn’t mean they weren’t delivered. Based on what I have read in the thread, the issue is either spam box, server settings or some other code you’re integrating with that you aren’t providing here.

One other thing, I noticed the file format you posted in the starting post and it’s a Word doc of some kind. I truly hope you are not coding in Microsoft Word. It’s not a recommended program to use to write code. Word inserts hidden data in the file that can inadvertently be copied to the actual code file and would be hidden from view there too. At the very least use basic Notepad or better yet Notepad++ which is also free.

I realize you don’t know PHP, but a you may want to look into PHPMailer. You would then be sending it through an SMTP server, which means it is not being sent by your server.

If that was the case, when the code is written the following format, emails should not go through either, but it does (just can’t reply because senders email is the phone#)
$field_name = $_POST[‘cf_name’];
$field_email = $_POST[‘cf_email’];
$field_email = $_POST[‘cf_phone’];
$field_message = $_POST[‘cf_message’];

In any case, I will try what you are suggesting tonight after school.

Thanks a lot.

To fastsole and astonecipher, thanks.

Nothing in spam. The only difference between receiving email in my inbox or not depends on how line 3 is written.

My website was created in Dreamweaver. I only pasted the codes in Wordpad for this forum.
There are no other codes involved except some codes in the contact.html that creates the page banner and footer and do not interfere with the Form code.

When I called my Host, they ran a script test for my contact page and the mail goes through according to them. Their test Mailer detail shows that they used SMTP. I asked if I have to set anything specific on my account for my email to work and they said no!
My domain is registered with someone else other than my Host. They tell me they don’t have anything to do with my email either.

From now on, please use the forum code tag button to paste in code. It’s the php and # button just above the emoticons.

Sponsor our Newsletter | Privacy Policy | Terms of Service