Jump to content

Email From Php


mdevelle
 Share

Recommended Posts

I fussed around with setting up a "Contact Us" page in my site and came up with this PHP script, with the help of Essential PHP Tools (D. Sklar, apress books) and the PEAR Mail Extension from the PEAR Website. I used a form in the final version, but the basic mechanics are here:

 

<?php

require 'Mail.php'; \\ From the PEAR mail package

$mailer =& Mail::factory('sendmail'); \\ Create object using the sendmail driver

$to = 'addressee@wherever.com'; \\ Where to send it

$headers = array('From' => 'sendermailname@senderaddress.com',

'Subject' => 'Hungry?',

'Cc' => 'sendheretoo@anotheraddress.com');

/* The cc: does not work right ... yet */

 

/* Create a body of text */

$body=<<<_MSGx_

Are you hungry? Wouldn't you like a cold,

sweet ice cream cone?

Why not stop by your local

ice cream parlor today for a few

scoops of Guava Mint

Bouillon?

 

Sincerely,

Your local ice cream booster

_MSGx_;

 

$res = $mailer->send($to, $headers, $body); \\ the send() method does the work

 

// If the message can't be sent, send() returns a

// PEAR::Error object

if (PEAR::isError($res)) {

print "Couldn't send message: " . $res->getMessage();

}

?>

Link to comment
Share on other sites

By using the normal PHP mail command and some variables, you can easily send emails:

 

<?php

$to = "yourplace@******";

$subject = "My email.";

$message = "message text goes here";

 

$headers = "From: myplace@here.com\r\n";

$headers .= "Reply-To: myplace2@here.com\r\n";

$headers .= "Return-Path: myplace@here.com\r\n";

$headers .= "CC: sombodyelse@noplace.com\r\n";

$headers .= "BCC: hidden@special.com\r\n";

 

if ( mail($to,$subject,$message,$headers) ) {

echo "The email has been sent!";

} else {

echo "The email has failed!";

}

?>

 

 

htmlite has a pretty clear and complete thing about using the mail command (i find it usefull):

http://www.htmlite.com/php029.php

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...