Newbie needs php help with email and his forum. Please.
Moderator: General Moderators
Newbie needs php help with email and his forum. Please.
I am on a Mac OSX Server 10.2.6, and I have php version 4.3.0 installed.
When I send an email out from one of my mail apps, everything is fine. But if I try to send mail out from inside my forum software, there is a problem. The diagnostic provided by the forum software tells me to verify that my PHP is being allowed to send mail.
How do I do this?
I can view my PHP Stats window. I am sure it is not called that, but since I have no idea what it is called.....
I see a line that reads
sendmail_from no value
sendmail_path /usr/sbin/sendmail -t -i
Is this correct? If not, how can I change it?
Thanks for any help.....
Signed,
A forum with a failure to communicate.
When I send an email out from one of my mail apps, everything is fine. But if I try to send mail out from inside my forum software, there is a problem. The diagnostic provided by the forum software tells me to verify that my PHP is being allowed to send mail.
How do I do this?
I can view my PHP Stats window. I am sure it is not called that, but since I have no idea what it is called.....
I see a line that reads
sendmail_from no value
sendmail_path /usr/sbin/sendmail -t -i
Is this correct? If not, how can I change it?
Thanks for any help.....
Signed,
A forum with a failure to communicate.
Last edited by aric on Sat Jul 12, 2003 11:23 am, edited 2 times in total.
thank you for your reply.
I am using vBulletin3.0 build 4 on a Mac OSX.2.6 server.
Would you mind reading a short conversation that I have been having with one of the devlopers?
http://www.vbulletin.com/forum/showthread.php?t=75713
What he is now telling me is that I need to make sure that my PHP is configured correctly to communcate with my mail server. If you would like, I can post some of my mail logs.
I just need help, or I am never going to be able to get this forum off the ground. It is so frustrating to come this far and then hit a bick wall.
I am using vBulletin3.0 build 4 on a Mac OSX.2.6 server.
Would you mind reading a short conversation that I have been having with one of the devlopers?
http://www.vbulletin.com/forum/showthread.php?t=75713
What he is now telling me is that I need to make sure that my PHP is configured correctly to communcate with my mail server. If you would like, I can post some of my mail logs.
I just need help, or I am never going to be able to get this forum off the ground. It is so frustrating to come this far and then hit a bick wall.
Have you found any utilities for configuring your server's SMTP server? I'm not sure, but OS X might use sendmail. If so, you'll need to comment out a few lines in sendmail.cf regarding security. because by default sendmail tends to refuse to send mail to other hosts, it just wants to deliver it locally. So yea, is there any mail server configuration utility, or sendmail.cf file?
(Quoted directly from geocrawler):
Code: Select all
Does /etc/mail/access contain?:
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
192.168.1 RELAY
and /etc/mail/relay-domains:
.net
.com
.org
.be
.nlI too have experienced problems with sendmail. I fixed my problem by ignoring sendmail and using prebuilt SMTP classes. The advantage of this was that I no longer depended on the sendmail daemon and could just rifle off messages using the local SMTP server. (port 25 must be open.)
mime_mail.php
smtp_mail.php
Just include the two above files and make your call
I hope this helps?
mime_mail.php
Code: Select all
<?
// store as "mime_mail.inc"
class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;
/*
* void mime_mail()
* class constructor
*/
function mime_mail() {
$this->parts = array();
$this->to = "";
$this->from = "";
$this->subject = "";
$this->body = "";
$this->headers = "";
}
/*
* void add_attachment(string message, їstring name], їstring ctype])
* Add an attachment to the mail object
*/
function add_attachment($message, $name = "", $ctype = "application/octet-stream") {
$this->partsї] = array (
"ctype" => $ctype,
"message" => $message,
"encode" => $encode,
"name" => $name
);
}
/*
* void build_message(array part=
* Build message parts of an multipart mail
*/
function build_message($part) {
$message = $partї "message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
return "Content-Type: ".$partї "ctype"].
($partї "name"]? "; name = "".$partї "name"].
""" : "").
"\nContent-Transfer-Encoding: $encoding\n\n$message\n";
}
/*
* void build_multipart()
* Build a multipart mail
*/
function build_multipart() {
$boundary = "b".md5(uniqid(time()));
$multipart =
"Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";
for($i = sizeof($this->parts)-1; $i >= 0; $i--)
{
$multipart .= "\n".$this->build_message($this->partsї$i]).
"--$boundary";
}
return $multipart.= "--\n";
}
/*
* string get_mail()
* returns the constructed mail
*/
function get_mail($complete = true) {
$mime = "";
if (!empty($this->from))
$mime .= "From: ".$this->from. "\n";
if (!empty($this->headers))
$mime .= $this->headers. "\n";
if ($complete) {
if (!empty($this->to)) {
$mime .= "To: $this->to\n";
}
if (!empty($this->subject)) {
$mime .= "Subject: $this->subject\n";
}
}
if (!empty($this->body))
$this->add_attachment($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n".$this->build_multipart();
return $mime;
}
/*
* void send()
* Send the mail (last class-function to be called)
*/
function send() {
$mime = $this->get_mail(false);
mail($this->to, $this->subject, "", $mime);
}
}; // end of class
?>Code: Select all
<?php
/*
* save as "smtp_mail.php"
*/
class smtp_mail {
var $fp = false;
var $lastmsg = "";
/*
* read_line() reads a line from the socket
* and returns the numeric code and the rest of the line
*/
function read_line()
{
$ret = false;
$line = fgets($this->fp, 1024);
if(ereg("^(ї0-9]+).(.*)$", $line, &$data)) {
$recv_code = $dataї1];
$recv_msg = $dataї2];
$ret = array($recv_code, $recv_msg);
}
return $ret;
}
/*
* dialogue() sends a command $cmd to the remote server
* and checks whether the numeric return code is the one
* we expect ($code).
*/
function dialogue($code, $cmd)
{
$ret = true;
fwrite($this->fp, $cmd."\r\n");
$line = $this->read_line($this->fp);
if($line == false) {
$ret = false;
$this->lastmsg = "";
} else {
$this->lastmsg = "$lineї0] $lineї1]";
if($lineї0] != $code) {
$ret = false;
}
}
return $ret;
}
/*
* error_message() prints out an error message,
* including the last message received from the SMTP server.
*/
function error_message()
{
echo "SMTP protocol failure (".$this->lastmsg.").<br>";
}
/*
* crlf_encode() fixes line endings
* RFC 788 specifies CRLF (hex 0x13 0x10) as line endings
*/
function crlf_encode($data)
{
# make sure that the data ends with a newline character
$data .= "\n";
# remove all CRs and replace single LFs with CRLFs
$data = str_replace("\n", "\r\n", str_replace("\r", "", $data));
# in the SMTP protocol a line consisting of a single "." has
# a special meaning. We therefore escape it by appending one space.
$data = str_replace("\n.\r\n", "\n. \r\n", $data);
return $data;
}
/*
* handle_email() talks to the SMTP server
*/
function handle_email ($from, $to, $data)
{
# split recipient list
$rcpts = explode(",", $to);
$err = false;
if(!$this->dialogue(250, "HELO phpclient") ||
!$this->dialogue(250, "MAIL FROM:$from")) {
$err = true;
}
for($i = 0; !$err && $i < count($rcpts); $i++) {
if(!$this->dialogue(250, "RCPT TO:$rcptsї$i]")) {
$err = true;
}
}
if($err || !$this->dialogue(354, "DATA") ||
!fwrite($this->fp, $data) ||
!$this->dialogue(250, ".") ||
!$this->dialogue(221, "QUIT")) {
$err = true;
}
if($err) {
$this->error_message();
}
return !$err;
}
/*
* connect() connects to an SMTP server on the well-known port 25
*/
function connect($hostname)
{
$ret = false;
$this->fp = fsockopen($hostname, 25);
if($this->fp) {
$ret = true;
}
return $ret;
}
/*
* send_email() connects to an SMTP server, encodes the message
* optionally, and sends $data. The envelope sender address
* is $from. A comma-separated list of recipients is expected in $to.
*/
function send_email($hostname, $from, $to, $data, $crlf_encode = 0)
{
if(!$this->connect($hostname)) {
echo "cannot open socket<br>\n";
return false;
}
$line = $this->read_line();
$ret = false;
if($line && $lineї0] == "220") {
if($crlf_encode) {
$data = $this->crlf_encode($data);
}
$ret = $this->handle_email($from, $to, $data);
} else {
$this->error_message();
}
fclose($this->fp);
return $ret;
}
}
?>Code: Select all
include ("mime_mail.php");
include ("smtp_mail.php");
$email = "destinationaddress@somewhere.com";
# our relaying SMTP server (Globals are specified in the main include.php)
$smtp_server = "your.smtpservername.com";
# the sender address
$from = "From address";
# the recipient(s)
$to = $email;
# the subject of the e-mail
$subject = "Subject of the message";
# ... and its body
$body = "Your message body
Multiple lines are allowed of course ;)";
# create mime_mail instance
$mail = new mime_mail;
$mail->from = $from;
$mail->to = $to;
$mail->subject = $subject;
$mail->body = $body;
# get the constructed e-mail data
$data = $mail->get_mail();
# create smtp_mail instance
$smtp = new smtp_mail;
# send e-mail
$smtp->send_email($smtp_server, $from, $to, $data);The third box of code would be on the page where you want to send an email from.
So you would include the first two class files (one for MIME, one for SMTP) and then call it as you need them.
You would need to change these lines to reflect your SMTP settings/scenario:
The rest of the code is used to make the message call... It works pretty good for me (some of my comments in the code might not apply -- I snipped the code out of a much larger application)
Hope it works for you.
So you would include the first two class files (one for MIME, one for SMTP) and then call it as you need them.
You would need to change these lines to reflect your SMTP settings/scenario:
Code: Select all
$email = "destinationaddress@somewhere.com";
# our relaying SMTP server (Globals are specified in the main include.php)
$smtp_server = "your.smtpservername.com";
# the sender address
$from = "From address";
# the recipient(s)
$to = $email;
# the subject of the e-mail
$subject = "Subject of the message";
# ... and its body
$body = "Your message bodyHope it works for you.