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 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2013
    Location
    Bangalore, Karnataka
    Posts
    43
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Php mail function

    How can use the mail function can one explain me? give me some examples?

  • #2
    New Coder
    Join Date
    Jul 2009
    Location
    UK
    Posts
    89
    Thanks
    5
    Thanked 11 Times in 11 Posts
    A quick Google for PHP mail brings up loads of examples
    http://php.net/manual/en/function.mail.php
    http://www.w3schools.com/php/php_mail.asp

    PHP Code:
    $to "example@example.com";
    $subject "My subject";
    $message "user message";
    mail($to$subject$message); 
    I'd love to change the world, but they wont give me the source code.

  • #3
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <form method="post" name="contactform" action="formmail.php" >

    <ul>
    <li><label for="first_name">Your name</label> <br/><input type="text" name="first_name" value=""></li>

    <li><label for="email">Your email address</label><br/><input type="text" name="email" value=""></li>
    <li><label for="telephone">Phone number</label><br/><input type="text" name="telephone" value=""></li>
    <li><label for="comments">Comments</label> <br/><textarea name="comments" rows="3" cols="17" id="msg"></textarea></li>
    <li><input style="color:#FFF; background:#206D9E;" type="submit" value="Submit" name="submit"></a></li>
    </ul>

    </form>

    An example
    The above page wud be ur suppose form page or say to enter details


    The below page is ur formmail.php page



    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "mail@domain.com";
    $email_subject = "Subject u want.";


    function died($error) {
    // your error code can go here

    echo $error."<br /><br />";
    echo "Please fill the form again.<br /><br />";
    die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||

    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted. Fill all fields precisely.');
    }

    $first_name = $_POST['first_name']; // required

    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }
    $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The name you entered does not appear to be valid.<br />';
    }

    if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
    }
    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";

    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";


    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);


    <!-- include your own success html here -->

    Thank you for contacting us. We will be in touch with you very soon.

    ?>


  •  

    Tags for this Thread

    Posting Permissions

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