...

View Full Version : Contact Form - from and reply to e-mails incorrect



Mehdi72
07-20-2007, 11:26 PM
I am trying to add a contact form to my website. I've send several test messages and the e-mail addresses listed in the from and reply to fields are incorrect :

Subject : blah
From : webmaster@example.com
Reply-To : webmaster@example.com
Date : 22:24
To : me@myemailaddress.com

Also I want messages posting sent to two e-mail addresses, how do I add an
additional e-mail address? Here's the php :



<?php

$headers = 'From: webmaster@example.com' . "\n" .
'Reply-To: webmaster@example.com' . "\n" ;
'X-Mailer: PHP/' . phpversion();

//CHANGE ME!
$to = "me@myemailaddress.com"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;



mail($to, $subject, $content, $headers);

?>

Thank you.

_Aerospace_Eng_
07-21-2007, 01:43 AM
This is what I use for my headers and everything seems to work fine with them.

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n" .
"Reply-To: webmaster@example.com";
To send the email to more than one address you can separate the addresses with a comma.

mail("$to, $to2", $subject, $content, $headers);

Mehdi72
07-21-2007, 01:50 AM
This is what I use for my headers and everything seems to work fine with them.

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n" .
"Reply-To: webmaster@example.com";
To send the email to more than one address you can separate the addresses with a comma.

mail("$to, $to2", $subject, $content, $headers);

Thanks but that didn't work. Could there be an error in the HTML?



<form method="POST" action="email.php">
Name: <input type="textbox" name="name" /><br />
Email Address: <input type="textbox" name="email" /><br />
Subject: <input type="textbox" name="subject"><br />
<textarea name="content">Insert email here</textarea>
<input type="submit" name="submit" value="Submit">
</form>

_Aerospace_Eng_
07-21-2007, 01:59 AM
Post all of your current code.

Mehdi72
07-21-2007, 02:05 AM
Post all of your current code.

Here's the php, messages are being sent to two addresses :


<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n" .
"Reply-To: webmaster@example.com";
'X-Mailer: PHP/' . phpversion();

//CHANGE ME!
$to = "blah@ blah.eu"; //Email address the comment will be sent to
$to2 = " blah2@blah2.com"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("$to, $to2", $subject, $content, $headers);

?>

Thank you.


I'll post the HTML once I've cleaned it up.

_Aerospace_Eng_
07-21-2007, 02:08 AM
Figures, you just copy and pasted what I gave you. Now you have an error in your code. Change this

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n" .
"Reply-To: webmaster@example.com";
'X-Mailer: PHP/' . phpversion();
to this

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

Mehdi72
07-21-2007, 02:19 AM
I uploaded the php and html to two domains but am still having the same problem.



<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

//CHANGE ME!
$to = "test@test.eu"; //Email address the comment will be sent to
$to2 = "test@test.com"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("$to, $to2", $subject, $content, $headers);

?>

Thank you.

_Aerospace_Eng_
07-21-2007, 02:25 AM
Tell us what isn't working?

Mehdi72
07-21-2007, 02:35 AM
Tell us what isn't working?

I'll give you an example. If I enter support@codingforums.com in the contact form the from and reply-to fields still read :

From : webmaster@example.com
Reply-To : webmaster@example.com

Instead of :

From : support@codingforums.com
Reply-To : support@codingforums.com

Sorry if I didn't make that clear.

_Aerospace_Eng_
07-21-2007, 03:00 AM
So which box do you want to be the reply-to and which one do you want to be the from?

Mehdi72
07-21-2007, 03:02 AM
So which box do you want to be the reply-to and which one do you want to be the from?

That's not the issue. I want the From and Reply-To fields to show the e-mail address that is actually entered in the contact form instead of showing webmaster@example.com

_Aerospace_Eng_
07-21-2007, 03:04 AM
Thats what I'm asking. Which text box from the form do you want to be the from address and which box did you want to be the reply email. It helps if you read things fully and try to understand what they mean. Try this

<?php

//CHANGE ME!
$to = "test1@domain.com"; //Email address the comment will be sent to
$to2 = "test2@otherdomain.com"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromn <$frome>\r\n";
$headers .= "Reply-To: $fromme\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("$to, $to2", $subject, $content, $headers);

?>
I also suggest that you do some more php tutorials as this is a very simple question. In the future explain yourself better.

Mehdi72
07-21-2007, 03:53 AM
Thats what I'm asking. Which text box from the form do you want to be the from address and which box did you want to be the reply email. It helps if you read things fully and try to understand what they mean. Try this

I also suggest that you do some more php tutorials as this is a very simple question. In the future explain yourself better.

Thanks. Only problem now is that despite listing two e-mail addresses the messages are only posted to one of them :



<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

//CHANGE ME!
$to = "test1@test.com"; //Email address the comment will be sent to
$to2 = "test1@testing.com"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromn <$frome>\r\n";
$headers .= "Reply-To: $fromme\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("$to, $to2", $subject, $content, $headers);

?>

Thank you.

_Aerospace_Eng_
07-21-2007, 05:32 AM
Hmm it should be sending it to both emails. Try this

mail("".$to.",".$to2."", $subject, $content, $headers);

CFMaBiSmAd
07-21-2007, 06:08 AM
The multi email To: syntax is correct. If the syntax was incorrect, it would probably not be able to figure out what to do with either one and would not be sending anything to either address. Since it is sending to one, there is probably a different reason why it is not sending to the other.

I suspect something like the email address it is sending to is hosted on the mail server where the php script is running and the email address it is not sending to is not hosted on the mail server where the php script is running and the mail server is setup to require authentication to relay email...

Mehdi72, can you tell us where each of the To: email address are hosted relative to where the php script is running?

_Aerospace_Eng_
07-21-2007, 06:26 AM
Thats what I thought as well however using this syntax

mail("$to, $to2", $subject, $content, $headers);
it doesn't work. Using this syntax, it does

mail("".$to.",".$to2."", $subject, $content, $headers);

Mehdi72
07-21-2007, 01:49 PM
The multi email To: syntax is correct. If the syntax was incorrect, it would probably not be able to figure out what to do with either one and would not be sending anything to either address. Since it is sending to one, there is probably a different reason why it is not sending to the other.

I suspect something like the email address it is sending to is hosted on the mail server where the php script is running and the email address it is not sending to is not hosted on the mail server where the php script is running and the mail server is setup to require authentication to relay email...

Mehdi72, can you tell us where each of the To: email address are hosted relative to where the php script is running?

One domain is hosted on register1.net and the other on servage.com. I removed the second e-mail address string and tried each e-mail address individually, the mail sent to servage is collected the mail sent to register1.net isn't. However mail sent to both domains was collected before Aerospace_Eng resolved the to and from issue on post 12 of this thread. Here's the full code :



<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

//CHANGE ME!
$to = "test@servage.com"; //Email address the comment will be sent to
$to2 = "test@register1.net"; //Email address the comment will be sent to

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromn <$frome>\r\n";
$headers .= "Reply-To: $fromme\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("".$to.",".$to2."", $subject, $content, $headers);

?>

Thank you.

Mehdi72
07-21-2007, 02:18 PM
When collecting mail in Thunderbird for the register1 domain recieving 1 of 1 is displayed but there is no mail in the inbox or deleted folder.

rafiki
07-21-2007, 02:34 PM
When collecting mail in Thunderbird for the register1 domain recieving 1 of 1 is displayed but there is no mail in the inbox or deleted folder.
what about junk/spam?

Mehdi72
07-21-2007, 02:39 PM
what about junk/spam?

All my spam ends up in the deleted folder.

Mehdi72
07-22-2007, 07:42 PM
Safe made was enabled on one of the php config files so I disabled it and changed the code to :



<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

//CHANGE ME!
$to = 'mehdi@soccer-europe.com, sales@seodesign.eu'; //Email address the comment will

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromn <$frome>\r\n";
$headers .= "Reply-To: $fromme\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$content = str_replace("\n.", "\n..", $_POST['content']);

mail("".$to."", $subject, $content, $headers);

?>

Thank you.


The time is displayed in the date field e.g.

Date : 19.32

How do I fix this so both the date and time are displayed?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum