Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP Mail

New Here ,
Aug 31, 2009 Aug 31, 2009

Hi all,

I created a form  (the information is send to the organizer via PHP and everything works fine) but I would like to know how to send to the participant a confirmation email.

<?php

$to = $_POST[['email']; 

$subject = "registration mail";

$message = "Hello! This is a confirmation message.";

$from = "me@mac.com";

$headers = "From: $from";

mail($to,$subject,$message,$headers);

?>

<?php

if (array_key_exists('send', $_POST)) {

  // mail processing script

  $to = 'me@mac.com'; // use your own email address

  $subject = 'Regitration';

  // process the $_POST variables

  $first = $_POST['first'];

  $last = $_POST['last'];

  $address = $_POST['address'];

  $city = $_POST['city'];

  $state = $_POST['state'];

  $zip = $_POST['zip'];

  $email = $_POST['email'];

  $fee = $_POST['fee'];

  $comment = $_POST['comment'];

  // build the message

  $message = "First: $first\r\n\r\n";

  $message .= "Last: $last\r\n\r\n";

  $message .= "Address: $address\r\n\r\n";

  $message .= "City: $city\r\n\r\n";

  $message .= "State: $state\r\n\r\n";

  $message .= "Zip: $zip\r\n\r\n";

  $message .= "Email: $email\r\n\r\n";

  $message .= "Entry fee: $fee\r\n\r\n";

  $message .= "Comments: $comment";

  $message = wordwrap($message, 500);

  // send it 

  $mailSent = mail($to, $subject, $message);

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>

<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

<!--

function MM_popupMsg(msg) { //v1.0

  alert(msg);

}

function MM_validateForm() { //v4.0

  if (document.getElementById){

    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args);

      if (val) { nm=val.name; if ((val=val.value)!="") {

        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

        } else if (test!='R') { num = parseFloat(val);

          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

            min=test.substring(8,p); max=test.substring(p+1);

            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

    } if (errors) alert('The following error(s) occurred:\n'+errors);

    document.MM_returnValue = (errors == '');

} }

//-->

function setfocus()

{

document.registration.first.focus();

}   

</script>

<style type="text/css">

<!--

#registration p {

color: #006;

font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;

font-size: 16px;

padding-left: 10px;

}

-->

</style>

</head>

<body onload="setfocus()">

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="registration" id="registration" onsubmit="MM_validateForm('first','','R','last','','R','phone','','R','email','','RisEmail','fee','','RisNum');return document.MM_returnValue">

  <p>

    <label for="first">First: </label>

    <input type="text" name="first" id="first" />

    <label for="last">Last: </label>

    <input type="text" name="last" id="last" />

  </p>

  <p>

    <label for="address">Address: </label>

    <input type="text" name="address" id="address" />

  </p>

  <p>

    <label for="city">City: </label>

    <input type="text" name="city" id="city" />

    <label for="state">State: </label>

    <input name="state" type="text" id="state" size="2" maxlength="2" />

    <label for="zip">Zip: </label>

    <input name="zip" type="text" id="zip" size="5" maxlength="5" />

  </p>

  <p>

    <label for="phone">Phone:</label>

    <input name="phone" type="text" id="phone" size="15" />

  </p>

  <p>

    <label for="email">Email:</label>

    <input name="email" type="text" id="email" size="30" />

  </p>

  <p>

    <label for="numberofgolfer">Number of golfer: </label>

    <select name="numberofgolfer" id="numberofgolfer">

      <option value="1" selected="selected">One</option>

      <option value="2">Two</option>

      <option value="3">Three</option>

      <option value="4">Four</option>

    </select>

  </p>

  <p>

    <label for="dinner">Extra dinner:</label>

    <input type="text" name="dinner" id="dinner" />

  </p>

  <p>

    <label for="fee">Entry fee:</label>

    $

    <input name="fee" type="text" id="fee" size="5" />

  </p>

  <p>

    <label>

      <input name="newreturning" type="radio" id="newreturning_0" onclick="MM_popupMsg('Welcome! Thanks for participating in our event!!!')" value="new" />

      New participant</label>

    </td>

    <label>

      <br />

      <input name="newreturning" type="radio" id="newreturning_1" onclick="MM_popupMsg('Welcome back')" value="returning" />

      Returnig golfer</label>

    </td>

  </p>

  <p>

    <label for="howhear">How did you hear about the golf tournament?</label>

    <select name="howhear" id="howhear">

      <option value="golf">From Golf Course</option>

      <option value="friend" selected="selected">Friend</option>

      <option value="flyer">Flyer</option>

      <option value="postcard">Postcard</option>

      <option value="email">Email</option>

      <option value="facebook">Facebook</option>

      <option value="mailing">Mailing</option>

      <option value="website">Website</option>

      <option value="other">Other</option>

    </select>

  </p>

  <p>

    <label for="comment">Comments: </label>

    <textarea name="comment" id="comment" cols="55" rows="5"></textarea>

  </p>

    <input name="send" type="submit" id="send" value="Send Form" />       <input type="reset" name="clear" id="clear" value="Reset" />

    <p>  

      <input name="" type="button" onClick="window.print()" value="Print This Page" />

  </span></p>

</form>

</body>

</html>

thanks

TOPICS
Server side applications
653
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 01, 2009 Sep 01, 2009
LATEST

All you're doing is sending two emails. Put one script after the other inside the if (array_key_exists('send', $_POST)) conditional statement.

However, if you are going to use the form input from the email field to send the email, it's absolutely vital to validate the email address before using it to send the message. If you don't, you risk turning your form into a spam relay.

The best way to do this, assuming your server supports PHP 5.2 or 5.3 is with the PHP filter functions.

if (array_key_exists('send', $_POST)) {

  if (filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {

    // build the first email and send it

    // then send the second email

  }

}

By the way, I see you have set wordwrap() to 500. For an email, wordwrap() should be set to something like 72.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines