PHP Mail Help!!!!

Discussion in 'PHP' started by mob4u1, Oct 14, 2009.

  1. #1
    i have a script to send mail using php... the form send the emails fine but th from part of the form doesn't seem to work... tried loads of variations but no joy... can you help!?

    THE FORM:
    <form action="process.php" method="post" />
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" size="50" />
    <label for="Number">Telephone:</label>
    <input type="text" name="Number" id="Number" size="50" />
    <label for="Email">Email:</label>
    <input type="text" name="Email" id="Email" size="50" />
    <label for="Enquiry">Enquiry:</label>
    <textarea name="Enquiry" id="Enquiry" rows="4" cols="50" ></textarea>
    <input name="submit" class="button" id="submit" type="submit" value="Send Enquiry" />
    
    HTML:
    THE PROCESS:
    <?php
    $EmailTo = "email@website.com";
    $Subject = "Website Enquiry"; 
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Number = Trim(stripslashes($_POST['Number'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Enquiry = Trim(stripslashes($_POST['Enquiry'])); 
    $Headers = "From: $Email" . "\r\n";
    $Headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $Headers .= "MIME-Version: 1.0" . "\r\n";
    
    // validation
    $validationOK=true;
    if (Trim($Name)=="") $validationOK=false;
    if (Trim($Number)=="") $validationOK=false;
    if (Trim($Email)=="") $validationOK=false;
    if (Trim($Enquiry)=="") $validationOK=false;
    if (!$validationOK) {
    
    echo "<h2>Oops...</h2><p>An error occurred and the message could not be sent, please try again...<br /><br />";
    echo "<br /><a href=\"javascript:history.go(-1);\">&laquo; Go Back</a></p>";
    } else {
    
    // email body
    $Body = "<html>" . "\r\n";
    $Body .= "<body>" . "\r\n";
    $Body .= "<br />";
    $Body .= $Subject;
    $Body .= "<br /><br />Name: ";
    $Body .= $Name;
    $Body .= "<br /><br />Telephone Number: ";
    $Body .= $Number;
    $Body .= "<br /><br />Email: ";
    $Body .= $Email;
    $Body .= "<br /><br />Enquiry: ";
    $Body .= $Enquiry;
    $Body .= "</body>" . "\n";
    $Body .= "</html>";
    
    $success = mail($EmailTo, $Subject, $Body, $Headers);
    
    echo "
    <h2>Thanks ".$Name."!</h2><p>Your message has been sent successfully.<br /><br />We will respond as soon as possible.</p>
    \n";
    }
    
    ?>
    
    PHP:
     
    mob4u1, Oct 14, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you just echo the $headers and show it here.
     
    premiumscripts, Oct 14, 2009 IP
  3. mob4u1

    mob4u1 Well-Known Member

    Messages:
    951
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Echo:
    From: Content-type: text/html; charset=iso-8859-1 MIME-Version: 1.0
     
    mob4u1, Oct 14, 2009 IP
  4. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try changing this line
    
    $success = mail($EmailTo, $Subject, $Body, $Headers);
    
    Code (markup):
    to

    
    $success = mail($EmailTo, $Headers, $Subject, $Body);
    
    Code (markup):
     
    organicCyborg, Oct 14, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    organic cyborg, why would you think that changing the order of the parameters (to an incorrect one) would solve this issue?

    Does $success equal true or false? Also display your errors, add this at the top:

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    PHP:
    If the email is being sent, it should be correct because mail will not be sent without a from header:

     
    premiumscripts, Oct 14, 2009 IP
  6. mob4u1

    mob4u1 Well-Known Member

    Messages:
    951
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #6
    took success out and still same... its sending it but from my server address : xxx.hostmonster.com
     
    mob4u1, Oct 14, 2009 IP
  7. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Heh, it looked out of order, being send to mail() towards the end. I'm not sure why I thought it was causing the problem.

    I tested the code and it worked fine for me.
     
    organicCyborg, Oct 14, 2009 IP
  8. mob4u1

    mob4u1 Well-Known Member

    Messages:
    951
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #8
    does it come through from the form from field value?
     
    mob4u1, Oct 14, 2009 IP
  9. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yep. It showed the value I entered in the form in fhe from field.
     
    organicCyborg, Oct 14, 2009 IP