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

0 Members and 1 Guest are viewing this topic.

Offline admin

  • Administrator
  • *****
  • Posts: 43
  • Karma: +1/-0
  • Gender: Male
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
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
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
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
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

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1834 Views
Last post May 09, 2008, 02:57:08 PM
by Roby
0 Replies
1513 Views
Last post June 19, 2007, 08:27:56 PM
by admin
0 Replies
4620 Views
Last post August 27, 2007, 04:03:48 AM
by peci
0 Replies
2219 Views
Last post February 10, 2009, 04:28:28 AM
by admin
0 Replies
206 Views
Last post January 30, 2010, 08:14:31 AM
by alex