Jump to content

Simple Mail Implementation


ev5unleash

Recommended Posts

Hi All,

 

I'm in the process of learning PHP and I don't know everything so please bare with me. I'm trying to have a simple e-mail script which will send a nice e-mails with variables from a previous form. I don't want to use my PHP servers predefined e-mail settings but define them myself. I plan on using G-Mail's SSL SMTP protocol. Upon looking up scripts for e-mailing I'm always coming across

 

 require_once "Mail.php";

 

in the code with no explanation on where that file is located. I'm currently using this code for to see if it works:

 

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";

$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, $body);

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

 

But I get the error

 

Fatal error: Class 'Mail' not found in C:\wamp\www\Quiz\sendmail.php on line 16

 

If anyone could be so kind to give me an explanation and assist me in understanding, that'd be great.

 

 

Thanks,

Evan

Link to comment
https://forums.phpfreaks.com/topic/262256-simple-mail-implementation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.