Sending mail
Information
none
Operating system used
Windows XP Home Edition Version 5.1 SP 2
Software prerequisites
PHP 4
Procedure
- Sending mail without SMTP authentication
- If you are hosting your website on your workstation and you are connected to
the internet by an ADSL/Cable connection and NO SMTP authentication
is required to send email then you need to modify your php.ini file.
Modify file c:\WINDOWS\php.ini. Change the following lines:
[mail function]
; For Win32 only.
SMTP = smtp.myisp.com
smtp_port = 25
; For Win32 only.
sendmail_from = [email protected]
SMTP |
Enter the SMTP server address of your ISP (=Internet Service Provider) |
sendmail_from | Enter your email address issued by the ISP |
If your website is hosted by a hosting provider then you do not need to edit the php.ini file.
- To send an email, create the following sendmail.php script:
<?php
/*
$user_email = $_REQUEST['Email'] ;
$message = $_REQUEST['Message'] ;
*/
$user_email = "[email protected]";
$message = "Hello World!";
$to_email = "[email protected]";
$subject = "Mobilefish.com Email";
mail( $to_email, $subject, $message, "From: $user_email" );
header( "Location: https://www.mobilefish.com/popupwindow/contact_thanks.html" );
?>
- Sending mail with SMTP authentication
- If you are hosting your website on your workstation and you are connected to
the internet by an ADSL/Cable connection and SMTP authentication
is required then you need to install the PEAR packages first.
In particular the PEAR Mail package.
See quick guide: Install PEAR.
- After PEAR is installed, you can now send an email. Create the following sendmail.php script:
<?php
require_once "Mail.php";
/*
$user_email = $_REQUEST['Email'] ;
$message = $_REQUEST['Message'] ;
*/
$user_email = "[email protected]";
$from_email = "[email protected]";
$to_email = "[email protected]";
$subject = "Mobilefish.com Email";
$message = "Hello World!" . "\n\n Message send from: " . $user_email;
$host = "smtp.myisp.com";
$username = "myaccount";
$password = "mypassword";
$headers = array ('From' => $from_email,'To' => $to_email,'Subject' => $subject);
$smtp = Mail::factory('smtp',array ('host' => $host,'auth' => true,'username' => $username,'password' => $password));
$mail = $smtp->send($to_email, $headers, $message);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
|