View Full Version : I can't send email with PHP

07-11-2009, 06:07 PM
I'm trying to send a test email form. I am running a test server (localhost) on my own machine using Apache

<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
<br />
<input type="submit" value="Submit" />


$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
echo $email."<br />";
echo $message."<br />";
$sentmail=mail( "andymoses@btinternet.com", "Feedback Form Results",$message, "From: $email \r\n" );

if ($sentmail) {
echo "email has been sent";
else {
echo "cannot send email";


So what I get on the screen is:
Test 9
cannot send email

I've changed my php.ini file:
[mail function]
; For Win32 only.
SMTP = mail.btinternet.com
smtp_port = 25

; For Win32 only.
sendmail_from = andymoses@btinternet.com

I don't get any error messages.
I am doing something(s) wrong? I've read that maybe BT stopped 3rd party emails through the SMTP, if so what SMTP could I use?

07-11-2009, 07:34 PM
For some reason i can't edit the original post. The form works fine when uploaded to my domain. I've since discovered that my ISP is btcentralplus.com. Does anyone know what the SMTP is for this?

07-14-2009, 09:21 PM
I've been wrestling with the same problem.
I got it to work. This is what works for me.

Part of php script:

$emess = "Thank you for joining bla bla bla.\n\n";
$emess.= "Your password is:\n\n ";
$emess.= "$password";
$subject = "Your new bla bla account";
$mailsend=mail("$email_address", "$subject", "$emess");
header("Location: anotherplace.php");

This is what I put into .ini:

[mail function]
; For Win32 only.
SMTP = smtp.eclipse.co.uk
smtp_port = 25
; For Win32 only.
sendmail_from = me@domain.eclipse.co.uk (me@domain.eclipse.co.uk)

The only dumb thing that I was doing was not changing the .ini file directly from the Wamp server dropdowns - I went straight to the file via bin and then changed it (but actually it didn't work - nothing changed).

I guess the point is that your script should be working because mine is basically the same. So, you are correct !
I found this - it might be useful.

Occasionally I have had trouble sending emails using the builtin mail() function (http://www.php.net/manual/en/function.mail.php) in PHP. Sometimes emails never reached their intended destination. A few days ago a friend of mine (http://www.2good.nu/) was asked to investigate the very same problem for a client.
The problem seems to be that PHP use the ini directive sendmail_from to set the from email address in the SMTP protocol. If this is not correctly set, or if it does not match the from header in the email headers, the email is caught by spam protection software.
The simplest solution is to set the directive during execution:
ini_set("sendmail_from", $email_from); $headers = "From: $email_from"; mail($to, $subject, $message, $headers);
Good luck -