Thread: Mail Function

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Mail Function


    So, I have a website which I have put a text box for people to type a testimonial in. Once they click submit, I want it to send what they typed to my email so I can review it before posting it. I am so confused by this SMTP and POP3 and stuff.

    The website is hosted with Cox Communications, and the email account I want the testimonials sent to is msn.

    For my html code I have this:

    Code:
    <form action="scripts/testimonial.php" method="post">
        <div id="test1">
      <label for="first_name">Submit a Testimonial</label>
        </div>
        <div id="test2">
      <input class="testimonial" type="text" name="testimonial" size="30" maxlength="200" />
        </div>
        
        <div id="submit">
      <input type="submit" value="Submit Testimonial" />
        </div>
                
    </form>


    And for the php I have this(I replaced my info with fake stuff):

    PHP Code:
    <?php
    $to 
    "myemail@live.com";
    $subject "Testimonial Submission";
    $message $_REQUEST['testimonial'];
    $from "My Website";

    mail($to$subject$message$from);
    echo 
    "Your testimonial has been received and will be reviewed.";
    echo 
    "If your testimonial is spam, it will not be shown.";
    echo 
    "Thank you for expressing your thoughts!";
    ?>
    Yes I know the mail server doesn't work on local host.
    But how do I get it took for real, on the actual website?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    Well i see a small syntax error. The mail function accepts the following parameters. (to, subject, message, additional headers) not from. so your code should be similar to this

    PHP Code:
    <?php 
    $to 
    "myemail@live.com"
    $subject "Testimonial Submission"
    $message $_REQUEST['testimonial']; 
    $header ='From: Website Forms <DoNotReply@example.com>'."\r\n";

    if (
    mail($to$subject$message$headers)){ 
    echo 
    "Your testimonial has been received and will be reviewed."
    echo 
    "If your testimonial is spam, it will not be shown."
    echo 
    "Thank you for expressing your thoughts!"
    }else{
    echo 
    "There was an error while submitting your form";

    }
    ?>
    Also remember that your dns must have an SPF record to prevent emails from your domain being treated as spam.

    Therefore you should

    Originally Posted by arro
    So, I have a website which I have put a text box for people to type a testimonial in. Once they click submit, I want it to send what they typed to my email so I can review it before posting it. I am so confused by this SMTP and POP3 and stuff.

    The website is hosted with Cox Communications, and the email account I want the testimonials sent to is msn.

    For my html code I have this:

    Code:
    <form action="scripts/testimonial.php" method="post">
        <div id="test1">
      <label for="first_name">Submit a Testimonial</label>
        </div>
        <div id="test2">
      <input class="testimonial" type="text" name="testimonial" size="30" maxlength="200" />
        </div>
        
        <div id="submit">
      <input type="submit" value="Submit Testimonial" />
        </div>
                
    </form>


    And for the php I have this(I replaced my info with fake stuff):

    PHP Code:
    <?php
    $to 
    "myemail@live.com";
    $subject "Testimonial Submission";
    $message $_REQUEST['testimonial'];
    $from "My Website";

    mail($to$subject$message$from);
    echo 
    "Your testimonial has been received and will be reviewed.";
    echo 
    "If your testimonial is spam, it will not be shown.";
    echo 
    "Thank you for expressing your thoughts!";
    ?>
    Yes I know the mail server doesn't work on local host.
    But how do I get it took for real, on the actual website?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by portcitysoftwar
    Well i see a small syntax error. The mail function accepts the following parameters. (to, subject, message, additional headers) not from. so your code should be similar to this

    PHP Code:
    <?php 
    $to 
    "myemail@live.com"
    $subject "Testimonial Submission"
    $message $_REQUEST['testimonial']; 
    $header ='From: Website Forms <DoNotReply@example.com>'."\r\n";

    if (
    mail($to$subject$message$headers)){ 
    echo 
    "Your testimonial has been received and will be reviewed."
    echo 
    "If your testimonial is spam, it will not be shown."
    echo 
    "Thank you for expressing your thoughts!"
    }else{
    echo 
    "There was an error while submitting your form";

    }
    ?>
    Also remember that your dns must have an SPF record to prevent emails from your domain being treated as spam.

    Therefore you should
    Okay, thank you. What do I do about it actually working?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    with those corrections it should work
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0
    So it will sent to my email and everything? Well when I upload it to my web host?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    if your webhost has php mail extension enbled

    Originally Posted by arro
    So it will sent to my email and everything? Well when I upload it to my web host?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0
    How would I enable it with cox communications business?
  14. #8
  15. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    400
    Rep Power
    311
    by the sounds of it you have not actually tried the script on the 'live' server. Try it out on the server even just with dummy info, it will probably work fine. If not see what errors you get and go from there.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0
    Okay I will try that out, thanks for your help!

IMN logo majestic logo threadwatch logo seochat tools logo