Re: mail() and sendmail configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dpgirago@xxxxxxxxxxxxxx wrote:

Good Morning,

This post is somewhat OT -- please forgive me. I've spent over 3 days trying to get sendmail configured and I've lost some patience and reasoning ability in the process.

I have a Linux (RH9), Apache 2.0.48, PHP 4.3.4, MySQL GUI that creates a PDF document on the server for web access. We would also like to have the document emailed to several folks within the company. So I essentially have to get the PDF attached to an email and routed to our SMTP server. I have webmin installed and have tried to use it to configure sendmail. When I execute /etc/rc.d/init.d/sendmail status --- Linux says that sendmail is running.

I'm using this method for creating emails with attachments (which was posted on the PHP-WIN list several months ago ), but it is failing:

<?php $fileatt = ""; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = ""; // Filename that will be used for the file as the attachment

$email_from = ""; // Who the email is from $email_subject = ""; // The Subject of the email $email_txt = ""; // Message that the email has in it

$email_to = ""; // Who the email is too $headers = "From: ".$email_from;

$file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file);

$semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_txt . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) { echo "<font face=verdana size=2>The file was successfully sent!</font>";

} else { die("Sorry but the email could not be sent. Please go back and try
again!"); } ?>


I've examined the content of the variables in this expression (from above) [[$ok = @mail($email_to, $email_subject, $email_message, $headers) ]] and it looks ok, though I'm no expert, so I'm guessing that the problem lies within the sendmail configuration. Webmin has loads of config pages for sendmail, and I admit that they're overwhelming right now. It seemed to me at first a relatively simple task to have an email created on the server, and forwarded to our SMTP server for delivery, but I was obviously naiive in this assumption. If anyone has suggestions or knows of helpful links or tutorials, I'd be deeply obliged.

Thanks for reading this long post.

David

Sounds like a doozy of a problem. Fixing the local machine is a good thing, but to get around it you could use PEAR::Mail's smtp backend.


require_once('Mail.php');
$mail = Mail::factory('smtp',
                      array('host' => 'your.relay.com',
                            'port' => 25,
                            'auth' => true,
                            'username' => 'user',
                            'password' => 'pass'));
$mail->send('user@xxxxxxxxxxx',
            array('From' => 'me@xxxxxxxxxx',
                  'Subject' => 'Test e-mail'),
            'This is a test e-mail.');


Note that you can remove the port, auth, username, and password entries if you don't need them.


You can also use this with PEAR's Mail_Mime package to easily create and send multipart messages.

http://pear.php.net/package/Mail
http://pear.php.net/package/Mail_Mime

--
paperCrane <Justin Patrin>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux