# PHP and sSMTP

## Meeuw

I'm trying to send e-mail from PHP using sSMTP, /usr/sbin/sendmail is a nice link to /usr/sbin/ssmtp and I can send e-mail from mutt.

php.ini reads:

```
[mail function]

; For Win32 only.

; SMTP = localhost

; smtp_port = 25

; For Win32 only.

;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

sendmail_path = /usr/sbin/sendmail -t
```

and my test script is:

```
<?php

mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");

?>
```

I'm getting the following error from /var/log/apache2/error_log:

```
sendmail: No recipients supplied - mail will not be sent
```

I suppose php doesn't pass the "to e-mail address" to ssmtp as a parameter, and it requires -t:

 *Quote:*   

>        -t     Read  message, searching for recipients. ``To:'', `Cc:'',  and ``Bcc:''  lines  will  be  scanned  for people to send to. Any addresses  in  the  argument list will be suppressed (not supported).

 

(enabling or disabling -t in php.ini give the same error)

Does someone have a fix for this? And if my assuption is right, who should fix this error, php or ssmtp?

----------

## tinwood

I was having similar problems getting PHP to play nice with postfix.  However, the problem I was having was the data from PHP was missing the 'From: ' in front of the sender address.

e.g. on your line:

 *Quote:*   

> 
> 
> ```
> 
> <?php 
> ...

 

Try

```

<?php 

mail("From: joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3"); 

?>

```

As for who should fix the problem, I actually think that PHP's mail function using sendmail is a bit of a hack.  You could always use the mail object from the PEAR library:

```

<?

include("Mail.php");

$recipients = "mail_to@domain.mail";

$headers["From"]    = "mail_from@domain.mail";

$headers["To"]      = "mail_to@domain.mail";

$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = "smtp.server";

$params["port"] = "25";

$params["auth"] = true;

$params["username"] = "user";

$params["password"] = "password";

// Create the mail object using the Mail::factory method

$mail_object =& Mail::factory("smtp", $params);

$mail_object->send($recipients, $headers, $body);

?>

```

This came from the PHP web-site manual.

Cheers

Alex.

----------

## Meeuw

Thanks Alex! My issue is resolved

----------

## c0ff

 *Meeuw wrote:*   

> I'm getting the following error from /var/log/apache2/error_log:
> 
> ```
> sendmail: No recipients supplied - mail will not be sent
> ```
> ...

 

The solution is

```

php.ini:

sendmail_path = /usr/sbin/ssmtp -t -f

```

----------

## electrofreak

I am having trouble as well. I followed the above config change, and now I get this:

```
ssmtp: Cannot open mail:25
```

could this be because the stupid ISP blocks port 25 (which it does). If so, how do I possibly make mail sending work in general?

----------

