Hi;
I have Unix server and i have tried the following code to send an email:
==%26gt;
%26lt;?PHP
ini_set('error_reporting', E_ALL);
ini_set ("SMTP","193.188.87.163");
ini_set ("sendmail_path", "/usr/sbin/sendmail -t -i");
$Msg= "%26lt;Table%26gt;%26lt;tr%26gt;%26lt;td%26gt;Name %26lt;/td%26gt;%26lt;td%26gt;" .
$_REQUEST['Yname'] .
"%26lt;/td%26gt;%26lt;/tr%26gt;%26lt;tr%26gt;%26lt;td%26gt;Email%26lt;/td%26gt;%26lt;td%26gt;" .
$_REQUEST['Email'] .
"%26lt;/td%26gt;%26lt;/tr%26gt;%26lt;tr%26gt;%26lt;td%26gt;The message is%26lt;/td%26gt;%26lt;td%26gt; " .
$_REQUEST['body'] . "%26lt;/td%26gt;%26lt;/tr%26gt;%26lt;/table%26gt;";
$FMail = $_$_REQUEST ['Email'] ;
$TMail = "alaa@cmc-amman.gov.jo" ;
$MSub = "CMC-Web Mail" ;
$fromname= $_REQUEST['Yname'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $fromname %26lt;$FMail%26gt;" ;
if (mail ($TMail ,$MSub, $Msg,$headers))
echo "Your mail have been sent";
else
echo "Sorry, your mail cant be sent";
?%26gt;
==%26gt;
the code is successful on localhost but failed when i uploaded it to the server ==%26gt; why?
PHP Mail function with Unix OS?
$FMail is null because you're setting it improperly.
$FMail = $_$_REQUEST ['Email'] ;
should be
$FMail = $_REQUEST ['Email'] ;
The code executes fine because there's no PHP error with it in the technical sense. However, you include a bad header with your FROM field, which is probably gumming up the works and filling up your badmail folder.
Reply:Have you checked your error log? It may already tell you exactly why.
Here are a few possibilities.
Is your local machine a Windows system? The mail function in Windows will use the SMTP setting. On Unix it doesn't. On Unix it looks for sendmail.
Try eliminating the ini_set command for the sendmail_path. Usually a successful Unix installation PHP already knows where to find sendmail.
You can also eliminate the ini_set for SMTP since the Unix version ignores it.
Your HTML string in $Msg should start with %26lt;html%26gt; and end with %26lt;/html%26gt;.
For HTML email you may need a To header, and it should not use the "name %26lt;email%26gt;" format. Try using just the email address in both the To and From headers. They are interpreted differently in Unix compared to Windows.
I hope this helps.
Reply:Verify the IP address of SMTP server. If not working, then please provide some more details like what error occured!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment