Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Contact Form - from and reply to e-mails incorrect

    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 :

    Code:
    <?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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This is what I use for my headers and everything seems to work fine with them.
    Code:
    $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.
    Code:
    mail("$to, $to2", $subject, $content, $headers);
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    This is what I use for my headers and everything seems to work fine with them.
    Code:
    $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.
    Code:
    mail("$to, $to2", $subject, $content, $headers);
    Thanks but that didn't work. Could there be an error in the HTML?

    Code:
    <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>

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post all of your current code.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Post all of your current code.
    Here's the php, messages are being sent to two addresses :
    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" .
                "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.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Figures, you just copy and pasted what I gave you. Now you have an error in your code. Change this
    PHP Code:
    $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
    PHP Code:
    $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(); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    I uploaded the php and html to two domains but am still having the same problem.

    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@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.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Tell us what isn't working?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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.

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    So which box do you want to be the reply-to and which one do you want to be the from?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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 Code:
    <?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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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 :

    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 = "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.

  • #14
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Hmm it should be sending it to both emails. Try this
    PHP Code:
    mail("".$to.",".$to2.""$subject$content$headers); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #15
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,066
    Thanks
    2
    Thanked 319 Times in 311 Posts
    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?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •