Jump to content

help getting started with PEAR for SMTP authentication


croix

Recommended Posts

OK, so my host decided to change up our mail server, and now my mail function in PHP does not work, because I now need SMTP authentication.

I know the typical mail function does not provide for SMTP authentication, but there is a workaround with PEAR.

But, I dont quite get it.

So here is my existing mail code:

[CODE]<?php

if (isset($_POST['company'])) {
$company = $_POST['company'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$outside_us = $_POST['outside_us'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$store_type = $_POST['store_type'];
$comments = $_POST['comments'];
$referral = $_POST['referral'];

$msg = "Attention Sliquid! You have a new vendor request!
Company Name = {$company}
First Name = {$firstname}
Last Name = {$lastname}
Address = {$address1}
Address 2 = {$address2}
City = {$city}
State = {$state}
Zip = {$zip}
Country = {$country}
Shipping Info = {$outside_us}
Phone = {$phone}
Website = {$website}
Fax = {$fax}
Email = {$email}
Store Type = {$store_type}
Comments = {$comments}
Referred By = {$referral}";

Enter_New_Entry($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral);

ini_set(SMTP, "smtp.sliquid.com");
ini_set(smtp_port, 25);
ini_set(sendmail_from, "[email protected]");
$headers = "From: [email protected]\r\n";
$headers .= "BCC: [email protected]\r\n";
//mail(To, subject, content, header);
$to = "[email protected]";
$result  = mail($to, "New Vendor Request", $msg, $headers);
if( $result == 0 ) {
echo "error <br>";

}
}
function Enter_New_Entry
($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral) {

$cnx = odbc_connect( 'records_db' , 'Admin', '********' );
    if (!$cnx) {
        Error_handler( "Error in odbc_connect" , $cnx );
    }

    $SQL_Exec_String = "Insert Into distributors (company, firstname, lastname, address1, address2, city, state, zip, country, outside_us, phone, website, fax, email, store_type, comments, referral)
            Values ('$company', '$firstname', '$lastname', '$address1', '$address2', '$city', '$state', '$zip', '$country', '$outside_us', '$phone', '$website', '$fax', '$email', '$store_type', '$comments', '$referral')";

    $cur= odbc_exec( $cnx, $SQL_Exec_String );
    if (!$cur) {
        Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}

odbc_close($cnx); 
header("location: http://www.sliquid.com/verify.htm");

}

?>
[/CODE]


and here is what I have found on the PEAR workaround:

[CODE]<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    '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>");
}
?>[/CODE]


anyone got a quick lesson or link on how to adapt this?

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.