Jump to content

Mail() and SMTP


Lassie

Recommended Posts

Thanks to everbody who has previously tried to help me with this but unfortunately I am making no headway.
My mail function refuses to work.
I have set the php.ini
to reflect my server address which is on the same machine and set the send mail from field.

The settings are
[mail function]
SMTP=213.210.25.37
[email protected]

I have written a test script to check mail is working as follows
<?php

$to = "[email protected]";
$subj = "test";
$mess = "This is a test of the mail function";
$headers = "From:Hawkesley House<[email protected]>\r\n";
mail($to,$subj,$mess,$headers);

if ($mailsent){
 
  echo "Test message sent";
}
else {
  echo "There was an error";
}
exit();
?>
I have checked that the SMTP server on the machine works by getting it to send an email via telenet

I get the following error
Warning: Unknown error in c:\easyserv\www\e_cart7\test_mail3.php on line 7
There was an error
I have looked at the php manual but cant find an obviuos clue.
Can anyone help please. Is there a way to reveal the unknown error?
Desperate for advice.



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

Hi

Sorry i don't have any conclusive answers, but 1 or 2 suggestions...

1. Experminet with the SMTP server address dynamically:

in the code, (instead of php.ini)
  ini_set("SMTP", "localhost"); // try localhost and 127.0.0.1, some routers etc will not loopback on public ip addresses etc... can cause problems
  mail($to,$subj,$mess,$headers);
  ini_restore("SMTP");

2. Remove the sendmail_from directive/or the from section in $headers, the smtp server may be rejecting the mail if its from 2 different addresses(?)

3. Check that you smtp server software will relay for the from addresses, i'm not sure the windows config but in linux postfix you have config like
relaydomains=btinternet.com,yahoo.co.uk

Hope at least something there is helpful

Cheers,
tdw

Link to comment
https://forums.phpfreaks.com/topic/29525-mail-and-smtp/#findComment-135536
Share on other sites

You have:
[code]<?php
    mail($to,$subj,$mess,$headers);
 
    if ($mailsent){
   
    echo "Test message sent";
  }
  else {
    echo "There was an error";
  }
?>[/code]
but you don't set the variable $mailsent before the "if" statement.

Try:
[code]<?php
    $mailsent = mail($to,$subj,$mess,$headers);
 
    if ($mailsent){
   
    echo "Test message sent";
  }
  else {
    echo "There was an error";
  }
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/29525-mail-and-smtp/#findComment-135610
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.