Jump to content

SMTP and PHP mail() Function


devarishi

Recommended Posts

The given below code fragment attaches a Text File to an Email Message and sends it.

 

I am able to get emails on our internal email ID (domain) but not on any external email id (domain).

 

For example:

 

Email sent to: [email protected] will be successfully delivered

 

But Email sent to: [email protected] won't be delivered.

 

Note:  I am using SMTP Services on the localhost whereon I have IIS and my web site. I really need to send reports to our Internal Team and to some other team external to our organization and that is why its domain name is different from ours.

 

 

Moreover, if I use an SMTP server which is running in a UNIX/Linux Server the PHP Code, as given below, doesn't send the Body of the Message and also doesn't contain all the contents of the text file. However, email is being sent to an external email id such [email protected].

Can anybody hellp me with it?

 

I am looking for a way to Configure SMTP Services on Windows Server / XP such as that it can Relay Emails to External Domains as well.

 


$message = "Let us see if it works!";

$file = "Uploads/" . $ticketID . ".txt";
	$file_size = filesize($file);

$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);

$content = chunk_split(base64_encode($content));

$uid = md5(uniqid(time()));
$name = basename($file);

$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";

# These two lines to avoid SPAM:
$header .= "Message-ID: <[email protected]:>";
$header .= "X-Mailer: PHP v".phpversion()."\r\n"; 

$header .= "Content-type:text/html; charset=iso-8859-1\r\n\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= "".$message."\n"; 

$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";



#	.....................................................................................
#					Subject Line of the Email Message
#	.....................................................................................

$subjLine .= ' [Ticket# ';
$subjLine .= $ticketID;
$subjLine .= ']';
#	-------------------------------------------------------------------------------------


$status = @mail("[email protected],[email protected]", $subjLine, "", $header);

 

 

 

 

 

Can anybody explain me why I can't include the message-body in the message parameter in function():

@mail("[email protected],[email protected]", $subjLine, "", $header);

 

which is simply being put as "" in the function. If I type anything inside the quotes, it won't be displayed in the message body. Why do I need to compose my message in the "header" ? Is there any way to keep header and message-body separate in a Multi-Part Email as shown above?

 

Link to comment
https://forums.phpfreaks.com/topic/191429-smtp-and-php-mail-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.