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
sendmail_from=hawkesley_2jags@yahoo.co.uk

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

$to = "hawkesley_2jags@yahoo.co.uk";
$subj = "test";
$mess = "This is a test of the mail function";
$headers = "From:Hawkesley House<hawkeslehouse@btinternet.com>\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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.