LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Pear Mail Packege - support security through SSL ? (https://www.linuxquestions.org/questions/programming-9/php-pear-mail-packege-support-security-through-ssl-586976/)

fatrandy13 09-24-2007 09:17 AM

PHP Pear Mail Packege - support security through SSL ?
 
I have the Pear Mail package installed with php on my system, i need to use pear because the SMTP being used by my webmail account needs authentication (standard php mail() does not support this). Does anyone know that if SSL security is required by the mail server, is there anyway Pear Mail can support this. I've googled and found some clues that lead me to belive that it is possible, so i'm really just looking for any recomendations by people who have successfully done this. maybe some sample code to study.

thanks

muxman 07-27-2008 04:15 PM

Try this code with the pear mail package. It worked for me. I found it through google a while ago and kept a copy in a notepad for reference. It worked for me with my att email and with gmail which both use ssl.

try this:

Code:

<?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>");
 }
?>


phlinux 09-07-2009 12:22 AM

Thanks for posting this!
 
It seemed most other methods were so cryptic - this worked like a charm!:D

PSampras 08-23-2011 07:38 AM

Hi,
I have the Pear Mail package installed with php on my system, i want to send an e-mail using SSL.

This is my code in php file:
PHP Code:

$from $_SESSION['email'];
$cc $_SESSION['email'];
$headers = array('Return-Path' => $_SESSION['email'],
                     
'From'     => $from,
                     
'To'          => $to,
                     
'Subject'  => $subject,
                     
'Cc'       => $cc,
                     
'Disposition-Notification-To' => $from,
                     
'Content-Type' => 'multipart/mixed; boundary="' $boundary '"');

(...
same code to set bodyattachmentetc...)

$body $mime->get();
$hdrs $mime->headers($headers);

$ms_params['host']     = $_CONFIG['smtp_host'];
$ms_params['port']     = $_CONFIG['smtp_port'];
$ms_params['auth']     = $_CONFIG['smtp_auth'];
$ms_params['username'] = $_CONFIG['smtp_username'];
$ms_params['password'] = $_CONFIG['smtp_password']; 

$mail = &Mail::factory('smtp'$ms_params);
$recipients =  $to.",".$cc;
$res $mail->send($recipients$hdrs$body);

if (
PEAR::isError($res)) {
  echo 
"<p align=\"center\" style=\"font-weight:bold\">Il preventivo non è stato inviato via e-mail all'indirizzo \"$emailana\" <br/>" .
           
"Di seguito il messaggio di errore ricevuto:<br/>" .  $res->getMessage() . "</p>";
} else {
  echo 
"<p align=\"center\" style=\"font-weight:bold\">Il preventivo è stato inviato via e-mail all'indirizzo \"$emailana\"</p>";


In file config.php:
PHP Code:

"smtp_host" => "ssl://smtps.pec.***.it",
"smtp_port" => "465",
"smtp_auth" => true,
"smtp_username" => "smtp_username",
"smtp_password" => "smtp_password"

The function PEAR::isError returns false and output shows no error in procedure.
But i don't receive the expected email...

This is phpinfo: http://imageshack.us/photo/my-images...099862605.png/
It seems all ok with openssl packages.

Thank you in advance for the support.

Giuseppe


All times are GMT -5. The time now is 03:59 AM.