Sending email with PHP - PHP tutorial - php Form

Author Topic: Sending email with PHP - PHP tutorial  (Read 6655 times)

Offline admin

  • Administrator
  • *****
  • Posts: 67
  • Karma: +10/-0
  • Gender: Male
    • View Profile
Sending email with PHP - PHP tutorial
« on: June 18, 2007, 06:40:30 AM »


form.php



Code: [Select]
<form name="form" action="mail.php" method="POST">
<table width="100%" border="0">
<tr>
  <td width="120">Name</td>
  <td><input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #663300; BORDER: #000000 1px line ; BACKGROUND-COLOR: #F8F8F8" input name="name"  size="30"></td>
</tr>
<tr>
  <td width="120">E-mail</td>
  <td><input type=text style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #663300; BORDER: #000000 1px line ; BACKGROUND-COLOR: #F8F8F8" input name="emaile" size="30"></td>
</tr>
<tr>
  <td width="120" valign="top">Comments</td>
  <td><textarea name="comments" style="font-size: 13px; font-family: tahoma,arial; font-weight: bold; color: #663300; BORDER: #000000 1px line ; BACKGROUND-COLOR: #F8F8F8"  rows="5" cols="40"></textarea></td>
</tr>
<tr>
  <td>
  </td>
  <td>
  <input type="submit" name="Submit" value="Submit">&nbsp;<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</form>

mail.php


Code: [Select]
<?php
include('config.php');
$time date ("h:i A"); 
$date date ("l, F jS, Y");
$urlh getenv(HTTP_HOST);
$url "http://$urlh";
$IP $_SERVER['REMOTE_ADDR'];
$name $_POST['name']; 
$emaile $_POST['emaile'];
$comments $_POST['comments'];
$headers 'From: System Admin <noreply@domain.com>';
$email;
$subject "Info";
$body $_POST['body'];
$bodys "Message:\n$comments\nThis form was submitted on Your Web Site on\n $date at\n $time.\n From IP Address.$IP \n From E Address: $emaile\n Name: $name \nUrl: $url "
$IP $_SERVER['REMOTE_ADDR'];
$body $body $bodys;
mail($email$subject$body"From: $email");
?>


Thank You. <a href="javascript:window.close()">Close</a>

config.php

Code: [Select]
<?php
$email 
'my email adress'
?>
« Last Edit: May 25, 2008, 05:08:23 PM by admin »

Offline asasas

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Sending email with PHP - PHP tutorial
« Reply #1 on: December 13, 2008, 09:04:26 AM »
Awesome Post!

Could please make tutorial, how manage this with phpmyadmin.

thanks!

Offline caradais

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Sending email with PHP - PHP tutorial
« Reply #2 on: April 03, 2009, 04:32:34 AM »
Help... I'm not sure how / where to post this or if indeed it is allowed - but I've created a contact.html file and a contact.php form to enable email messages to come through from the site, but there are a couple of small glitches and I can't find where they might be.

http://www.malmesburysingers.co.uk/contact.html

The email that comes through is not html even tho I've said it should be (small coding error?)

I don't get a "thank you for your interest" message popping up once the form is completed

I cannot get the radio button to register when the email comes through.

If this message is inappropriate, could it be moved to the correct place if indeed someone can help?

Many thanks in advance.

Offline markspenser

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Sending email with PHP - PHP tutorial
« Reply #3 on: October 23, 2009, 04:21:07 AM »
Thanks for the code given... I was looking for same [urk=http://www.plaveb.com]php[/url] script since last long time...

again thanks...

Mark

Offline SPDPK

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Is this correct code for sending mail in php
« Reply #4 on: November 01, 2009, 09:00:49 PM »
<?php
                        $txtfirstname= $_REQUEST[name];
                        $from= $_REQUEST[email];
                        $txttelephone= $_REQUEST[telephone];
                        $txtComments= $_REQUEST[comments];
                        $subject = "Online Enquiry";
 
                        $to="info@xxxxxxxxxx.com";
 
                        $message="Name: ".$txtfirstname."\n\nEmail Id: ".$from."\n\nTelephone: ".$txttelephone."\n\n";
 
                        if($txtComments)
                        $message.="Comments: ".$txtComments."\n\n";
                  

$host = "smtp.bizmail.yahoo.com";
$port = "465";
$username = "info@xxxxxxxxxx.com";
$password = "xxxxxxxx";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $message);


if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
  header( "Location: thanks.html");
 } else {
  echo("<p>Message successfully sent!</p>");
  header( "Location: thanks.html");
 }


?>

djape

  • Guest
Re: Sending email with PHP - PHP tutorial
« Reply #5 on: November 02, 2009, 09:44:59 AM »
yes, with few PEAR packages... :D

Offline 4utumn

  • Supporter
  • **
  • Posts: 1
  • Karma: +2/-0
    • View Profile
Re: Sending email with PHP - PHP tutorial
« Reply #6 on: January 26, 2011, 11:53:22 PM »
I have here some sample codes of php tutorial in sending email with php. I got this some online site that I research in google. Hope this will help in your problem.
Code: [Select]
<html>
<head>
<title>Mail()</title>
</head>
<body>
<?php
 
if (!array_key_exists('Submitted',$_POST))
 {
?>

  <form method="post" action="Mail.php">
  <input type="hidden" name="Submitted" value="true"/>
  Mail Server: <input type="text" name="Host" size="25"/><br/>
  To: <input type="text" name="To" size="25"/><br/>
  From: <input type="text" name="From" size="25"/><br/>
  Subject: <input type="text" name="Subject" size="25"/><br/>
  <textarea name="Message" cols="50" rows="10"></textarea><br/>
  <input type="submit" value="Send Email"/>
  </form>
<?php
 
}
 else
 {
  
ini_set('SMTP',$_POST['Host']);
  
$To $_POST['To'];
  
$From 'From: ' $_POST['From'];
  
$Subject $_POST['Subject'];
  
$Message $_POST['Message'];
 
  if(
mail($To,$Subject,$Message,$From))
  {
   echo 
"Message Sent";
  }
  else
  {
    echo 
"Message Not Sent";
  }
 }
?>

</body>
</html>

My Sports Email