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.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email form not sending

    Hello All!

    Im new here and to php! Im having a few problems with a email form, i can get this to send

    PHP Code:
    <?php
    $to 
    "someone@example.com";
    $subject "Test mail";
    $message "Hello! This is a simple email message.";
    $from "someonelse@example.com";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    ?>
    But not this -

    PHP Code:
    <?php
    mail
    ('sales@vandiscount.co.uk','Test mail','The mail function is working!');
    echo 
    'Mail sent!';
    ?>
    This one gives me the error -

    Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\nas01\nas\v\a\vandiscount.co.uk\web\mailtest.php on line 2
    Mail sent!

    Then if i try this in my code it send but i receive nothing -

    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "sales@vandiscount.co.uk";
    $subject "Form Submission";
    $name_field $_POST['firstname1'];
    $email_field $_POST['companyname1'];
    $number_field $_POST['lastname1'];
    $time_field $_POST['mobile1'];
    $comments_field $_POST['phone1'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "message sent!";

    }
    ?>
    and heres what im actaully using as the mailform page, sorry for the large amount but its driving me insane! -

    PHP Code:
    <tr>

    <
    td bgcolor="#C0C0C0" width="148"><b>
    <
    font face="Arial">Contact us below</font></b><p align="center"><b>
    <
    font face="Arial" size="2">(Use the TAB Key to move down the form)</font></b></td>
    </
    tr>
    <
    tr>
    <
    td width="148" height="55">
    <
    b><font face="Arial" size="2">Your name</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:24" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="firstname1" size="20"></font></td></tr>
    <
    tr>
    <
    td height="50" width="148">
    <
    b><font face="Arial" size="2">Your number</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:25" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="lastname1" size="20"></font></td></tr>
    <
    tr>
    <
    td width="148" height="50">
    <
    b><font face="Arial" size="2">Your email</font></b><font face="Arial"><input style="width: 143;height:25" type="text" value="" name="companyname1" size="20"></font></td></tr>
    <
    tr>
    <
    td width="148">
    <
    b><font face="Arial" size="2">Your requirements</font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:132" title="Your Google Toolbar can fill this in for you. Select AutoFill" type="text" value="" name="phone1" size="20"></font></td></tr>
    <
    tr>
    <
    td width="148" height="52"><b><font face="Arial" size="2">Preferred time to 
    contact you
    </font></b><font face="Arial"><input style="width: 143; background-color: #ffffa0; height:22" type="text" value="" name="mobile1" size="20"></font></td></tr>
    <
    tr>
    <
    td align="center" width="148"><font face="Arial, Arial, Helvetica">
    <
    input class="sendbutton" type="submit" value="  Submit Form  " name="submit_apply1"> </font></td></tr></tbody></table

  • #2
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for any help at all guys, im very new to this but im a fast learner,

    Simon

  • #3
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    As the error message suggests your server requires a From: header to be set (most servers don't like 'anonymous' mail, though some will substitute a default from address).

    In your first example you are using the fourth parameter to the mail() call which is the additional headers parameter and passing it "From: $from" so it has a from address, in the second example you are not using the fourth parameter at all and hence not giving a from address.

    HTH,

    Dai

  • #4
    Regular Coder
    Join Date
    Nov 2009
    Location
    Scotland / Glasgow
    Posts
    184
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Just to reinforce what DaiWelsh said. I have a few flash+php mail forms on my blog that use headers in the mail function().

    I typical code would look like:
    PHP Code:
    $headers      "MIME-Version: 1.0\r\n"
    $headers     .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers     .= "From: your@email.com\r\n";
    $headers     .= "Reply-To: your@email.com\r\n";

    mail($to"Some subject"$msg$headers); 
    hope it helps
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help guys

    Going to give this below a try when home -

    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "sales@vandiscount.co.uk";
    $from "admin@vandiscount.co.uk";
    $subject "Form Submission";
    $name_field $_POST['firstname1'];
    $email_field $_POST['companyname1'];
    $number_field $_POST['lastname1'];
    $time_field $_POST['mobile1'];
    $comments_field $_POST['phone1'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "message sent!";

    }
    ?>

  • #6
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    No that won't work you need to use the fourth parameter for headers e.g.

    PHP Code:
    <?php
    $headers 
    =  "From: $from\nReply-To: $from\n";
    mail($to$subject$body,$headers);
    ?>
    Anything you pass in the third param will be part of the message body, headers (other than the default ones that get set by mail()) need to go in the fourth param (see docs).

    Regards,

    Dai

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    <?php 
    if(isset($_POST['submit'])) { 

        
    $to "sales@vandiscount.co.uk"
        
    $subject "Form Submission"
        
    $name_field $_POST['firstname1']; 
        
    $email_field $_POST['companyname1']; 
        
    $number_field $_POST['lastname1']; 
        
    $time_field $_POST['mobile1']; 
        
    $comments_field $_POST['phone1']; 

        
    $body 'Body here, just a test';
        
    $headers =  "From: $from\r\nReply-To: $from\r\n";    

        if (
    mail($to$subject$body$headers))
        {
            echo 
    "Data has been submitted to $to!"
        }
        else
        {
            echo 
    'Unable to send mail';
        }

    ?>
    If running the above produces output that mail was submitted, php is happy. If you're not receiving you're email, ensure that an smtp server has been configured in you're php.ini or pass it in as an argument to the 5th parameter. If you're locally served, ensure that you have an smtp service installed and configure it in you're php.ini file. If you're hosted, contact you're hosting company to ask what the sendmail path should be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    PHP Code:
    <?php 
    if(isset($_POST['submit'])) { 

        
    $to "sales@vandiscount.co.uk"
        
    $subject "Form Submission"
        
    $name_field $_POST['firstname1']; 
        
    $email_field $_POST['companyname1']; 
        
    $number_field $_POST['lastname1']; 
        
    $time_field $_POST['mobile1']; 
        
    $comments_field $_POST['phone1']; 

        
    $body 'Body here, just a test';
        
    $headers =  "From: $from\r\nReply-To: $from\r\n";    

        if (
    mail($to$subject$body$headers))
        {
            echo 
    "Data has been submitted to $to!"
        }
        else
        {
            echo 
    'Unable to send mail';
        }

    ?>
    If running the above produces output that mail was submitted, php is happy. If you're not receiving you're email, ensure that an smtp server has been configured in you're php.ini or pass it in as an argument to the 5th parameter. If you're locally served, ensure that you have an smtp service installed and configure it in you're php.ini file. If you're hosted, contact you're hosting company to ask what the sendmail path should be.

    Just tried this and i dont receive any mail, ive opened a ticket with namesco to ask what the sendmail path should be. Ive also requested to move from windows hosting to linux.

  • #9
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok ive manage to get one of the fields working but non of the others and heres how ive got to that -

    PHP Code:
    <?php 
    $to 
    "sales@vandiscount.co.uk";
    $subject "Online Mail Form";
    $from "admin@vandiscount.co.uk";
    $headers "From: $from";
    $name_field $_POST['firstname1'];
    $email_field $_POST['companyname1'];
    $number_field $_POST['lastname1'];
    $time_field $_POST['mobile1'];
    $comments_field $_POST['phone1'];
    mail($to,$subject,$comments_field,$headers);
    echo 
    "Mail Sent.";
    ?>
    But in the 10thline i cant add more than 5 parameters can i? how can i add the others in?

  • #10
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The errors i get if i add any other _field in is -

    Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\nas01\nas\v\a\vandiscount.co.uk\web\thanks.php on line 20
    Mail Sent.

  • #11
    Regular Coder
    Join Date
    Nov 2009
    Location
    Scotland / Glasgow
    Posts
    184
    Thanks
    1
    Thanked 19 Times in 19 Posts
    You have already been shown how the header should be formed.
    PHP Code:
     $headers =  "From: $from\r\nReply-To: $from\r\n"
    Most probably the missing field is replyTo
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher


  •  

    Posting Permissions

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