mail(); header problem

Discussion in 'PHP' started by Scorpiono, Jan 6, 2009.

  1. #1
    mail($adminemail, $subj, $msg, "FROM: $name\r\nReply-to: $from\r\nContent-type: text/html; charset=iso-8859-1\r\n");
    Code (markup):
    Do you see any errors in the code above?

    $name,$from are grabbed via $_POST.

    It doesn't seem to work correctly.
    I do recieve it in HTML format, but the FROM is altered.
     
    Scorpiono, Jan 6, 2009 IP
  2. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure how you have manipulated the $_POST variables but $from needs to contain an email ...

     
    mallorcahp, Jan 6, 2009 IP
  3. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Should I echo and reply back? I think it's a \r\n problem more like $_POST problem.
     
    Scorpiono, Jan 6, 2009 IP
  4. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have the function running with both "\r\n" as well as just "\n" but worth a try. Also, thinking about it, no need for any line breaks after "... charset=iso-8859-1"

    I also have the function working with

    on one of my sites, change version to suit ...
     
    mallorcahp, Jan 6, 2009 IP
  5. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Does it matter in headers which comes first? From/Reply-to ?
     
    Scorpiono, Jan 6, 2009 IP
  6. JWRmedia

    JWRmedia Banned

    Messages:
    499
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Using the mail function with PHP is a little simpler than most people first think. Take a look over these PHP mail instructions. They will probably help you out.
     
    JWRmedia, Jan 7, 2009 IP
  7. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #7
    It's well written but still it doesn't point out using From: <> and Reply-To: in the same headers
     
    Scorpiono, Jan 7, 2009 IP
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    http://danltn.com/bin/o0q.phps

    Example usage:

    <?php
    
    $mail = new email;
    
    $mail->html_mail()->to('email@gmail.com')->subject('Hello')->message('Hello there <b>Person</b>. How are you?')->from('email@ymail.com')->header('Reply-To: reply@email.com')->send(); 
    PHP:
     
    Danltn, Jan 7, 2009 IP
  9. gjgroups

    gjgroups Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <?php
    $first_name = $_POST['firstname'];
    $company_name = $_POST['companyname'];
    $email = $_POST['emailaddress'];
    $phone_no = $_POST['phone_no'];
    $qstntype = $_POST['qstntype'];
    $country = $_POST['country'];
    $enquiry = $_POST['enquiry'];
    $mail_content ="<html>
    <head>
    <title></title>
    <style type='text/css'>
    .spanclassnrml{
    font-family:Arial;
    font-size:12px;
    color:#000000;
    }

    .tableclass{
    background-color:#CCCCCC;
    font-family:Arial;
    font-size:12px;
    font-style:normal;
    color:#000000;
    }
    .rowclass{
    background-color:#FFFFFF;
    }
    .tdheadclass{
    width:25%;
    }
    </style>
    </head>
    <body>
    <span class='spanclassnrml'><b>Dear Administrator</b>,</span><br /><br />
    <span class='spanclassnrml'>You have received an enquiry from <b>$first_name</b></span>
    <br />
    <br />
    <table class='tableclass' cellpadding='5' cellspacing='1' width=70%>
    <tr class='rowclass'>
    <td class='tdheadclass'><b>Company Name</b></td>
    <td>$company_name</td>
    </tr>
    <tr class='rowclass'>
    <td class='tdheadclass'><b>Country</b></td>
    <td>$country</td>
    </tr>
    <tr class='rowclass'>
    <td class='tdheadclass'><b>E-mail Address</b></td>
    <td>$email</td>
    </tr>
    <tr class='rowclass'>
    <td v><b>Phone #</b></td>
    <td>$phone_no</td>
    </tr>
    <tr class='rowclass'>
    <td v><b>Query Type</b></td>
    <td>$qstntype</td>
    </tr>";
    if($enquiry!=""){
    $mail_content .= "<tr class='rowclass'>
    <td class='tdheadclass'><b>Enquiry</b></td>
    <td>$enquiry</td>
    </tr>";
    }
    $mail_content .= "</table><br /><br />
    <span class='spanclassnrml'><b>Regards</b>,</span><br />
    <span class='spanclassnrml'>$first_name.</span><br /><br />
    <span class='spanclassnrml'><b>Note:</b> This is a system generated e-mail.</span></body>";


    $to = "santhobs@gmail.com";
    $from = "$email";
    $subject = "Query from E5 Website | $first_name";
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    mail($to, $subject, $mail_content, $headers);
    echo "Message Sent Successfully";
    ?>
     
    gjgroups, Jan 10, 2009 IP