LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-24-2007, 09:17 AM   #1
fatrandy13
Member
 
Registered: Jun 2004
Location: new jersey
Distribution: anything debian based, long live apt-get
Posts: 230

Rep: Reputation: 30
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
 
Old 07-27-2008, 04:15 PM   #2
muxman
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 198

Rep: Reputation: 30
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>");
 }
?>
 
Old 09-07-2009, 12:22 AM   #3
phlinux
LQ Newbie
 
Registered: Sep 2009
Posts: 1

Rep: Reputation: 0
Smile Thanks for posting this!

It seemed most other methods were so cryptic - this worked like a charm!
 
Old 08-23-2011, 07:38 AM   #4
PSampras
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP5 Upgrade Error: Missing Dependency: php = 4.3.x is needed by package php-pear vsystems Linux - Server 1 05-02-2007 07:17 AM
install Pear Net/SMTP, Pear Log and Pear DB modules cccc Debian 0 02-26-2007 08:33 AM
Problems compiling php with imap, ssl... support tveiga Linux - Software 1 01-16-2004 09:06 PM
pear support in Apache slamarca Linux - Software 3 08-06-2003 05:23 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM


All times are GMT -5. The time now is 02:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration