php email sending problem - please help

  • bluegene
  • Born
  • Born
  • bluegene
  • Posts: 2

Post 3+ Months Ago

hi can anybody please help me with a email send out issue?

ive got a input field named "your friends email address" when the user fills in the form he has to put his friends email in that field, then when he submits the form that email goes to his friend, so my problem is...... how do i do it? PLEASE HELP!!!!!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

where is your code in code bb, but any of the 10,000 tutorials out there should give you the layout of what to do.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

If a simple search is done in Google "php simple mailer" there are several ways of going about this and many tutorials like Zealous stated. To shed a bit of light on it you will be needing to make use of the mail function in PHP. When you submit the form with your friends email the page you set in the action attribute of the form tag will have to get the email by use of the $_POST or $_GET variable depending on how you setup your form. After you got that info you can make the subject and message to be sent to your friend. You could also add fields to the form for the subject and message and capture them the same ways as the email. Once you have the email, subject and the message you can setup the headers although they are not required.

Take a look at the example below

form.php
HTML Code: [ Select ]
<!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>Form Mailer</title>
</head>
 
<body>
<form id="form1" name="form1" method="post" action="form_mailer.php">
<table width="455" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="45" align="center"><label for="email">friends email</label></td>
    <td><input name="email" type="text" id="email" size="30" /></td>
  </tr>
  <tr>
    <td height="38">&nbsp;</td>
    <td><label>
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </label></td>
  </tr>
</table>
</form>
</body>
</html>
 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Form Mailer</title>
  6. </head>
  7.  
  8. <body>
  9. <form id="form1" name="form1" method="post" action="form_mailer.php">
  10. <table width="455" border="0" cellspacing="0" cellpadding="0">
  11.   <tr>
  12.     <td height="45" align="center"><label for="email">friends email</label></td>
  13.     <td><input name="email" type="text" id="email" size="30" /></td>
  14.   </tr>
  15.   <tr>
  16.     <td height="38">&nbsp;</td>
  17.     <td><label>
  18.       <input type="submit" name="Submit" id="Submit" value="Submit" />
  19.     </label></td>
  20.   </tr>
  21. </table>
  22. </form>
  23. </body>
  24. </html>
  25.  


form_mailer.php
PHP Code: [ Select ]
<?php
 
// Get the email from the post info
$friends_email = $_POST['email'];
 
// Make the subject and the message
$subject = 'This is a test message';
$message = 'This is the body of the message to be sent to the friends email';
 
// This takes the email and displays it as who this email is from.
$headers = "From: Someone@Somthing.com\r\n";
 
// This tells the server to turn the coding into the text.
$headers .= "Content-type: text/html\r\n";
 
// This tells the server what to send.
if(mail($friends_email, $subject, $message, $headers)) {
   
   // Kick to success page
   header("location: it_worked.php");
   
} else {
   
   // Kick to error page
   header("location: boo_it_failed.php");
   
}
 
 
?>
 
  1. <?php
  2.  
  3. // Get the email from the post info
  4. $friends_email = $_POST['email'];
  5.  
  6. // Make the subject and the message
  7. $subject = 'This is a test message';
  8. $message = 'This is the body of the message to be sent to the friends email';
  9.  
  10. // This takes the email and displays it as who this email is from.
  11. $headers = "From: Someone@Somthing.com\r\n";
  12.  
  13. // This tells the server to turn the coding into the text.
  14. $headers .= "Content-type: text/html\r\n";
  15.  
  16. // This tells the server what to send.
  17. if(mail($friends_email, $subject, $message, $headers)) {
  18.    
  19.    // Kick to success page
  20.    header("location: it_worked.php");
  21.    
  22. } else {
  23.    
  24.    // Kick to error page
  25.    header("location: boo_it_failed.php");
  26.    
  27. }
  28.  
  29.  
  30. ?>
  31.  

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 92 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.