Announcement

Collapse
No announcement yet.

Sending Email with php

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending Email with php

    I have seen this more and more often. some of you want to send emails to you or another address. well in php is it way easy.

    to start we need a form, this will do
    Code:
    <form action="test.php" method="post">
    <input type="text" values="" name="myname">
    <input type="submit" value="Submit" name="submit">
    </form>
    this will allow the user to enter a name in the form and have it submit to your email. now we don't neccassarily hav eto stop at a name so you can add more if you want.

    so the page it submits to text.php will look like this
    PHP Code:
    <?php
    $name 
    $_POST['myname'];
    $message "this the body of the email, Hi, $name";
    $subject "this is the subject of the email";
    $headers "From: you@someplace.com <you@someplace.com>\r\n";
    mail("your@email.com",$subject,$message$headers);
    very basic email, text only. if you want html email it is just a little more added.
    PHP Code:
    <?php
    $name 
    $_POST['myname'];
    $message =  "<html><head></head><body><br /><br />";
    $message .= "this the body of the email, Hi, $name";
    $message .= "<br /></body></html>";
    $subject "this is the subject of the email";
    $headers "From: you@someplace.com <you@someplace.com>\r\nContent-type: text/html";
    mail("your@email.com",$subject,$message$headers);
    of course there is a lot more you can add to that but that will send a very basic html email, pretty simple.

    for more information on email you can read up on it here: mail()
    Have a Script or Snippet you want to share?

    WWW Standards: HTML 4.01,
    HTML 5, CSS2.1, CSS3, XHTML 1.0
    PHP Standards: PHP Standards
Working...
X