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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.