Can you take a look at this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$emai=$_REQUEST['txtemai'];
$subj=$_REQUEST['txtsubj'];
$mess=$_REQUEST['txtmess'];
if (@mail($emai,$subj,$mess)) {
 echo('<p>Mail sent successfully.</p>');
} else {
 echo('<p>Mail could not be sent.</p>');
} 
?>
</body>
</html>

I keep on getting the else statements.

Here's the code from the form page this email page works with:

<form method="post" action="Emailed.php">
        <input name="txtemai" type="text" id="textfield" size="75" />
      </p>
      <p> Subject:        </p>
      <p>
        <input name="txtsubj" type="text" id="textfield" size="75" />
                  </p>
      <p>Message:
        <textarea name="txtmess" cols="87" rows="15" id="textarea"></textarea>
           
        <input name="button" id="button" type="submit" value="Send" />
         </form>
      </p>

Here is my php.ini in the mail portion of it:

[mail function]
; For Win32 only.
SMTP = smtp.va.com
smtp_port = 25

; For Win32 only.
sendmail_from = Admin@va.com

I am using Apache 2.2.8 and Win XP Pro SP2

Can anyone find a solution why I can't send emails to my test address in yahoo.com?

Is your smtp.va.com server a different server ? If so, are you sure it supports open relay smtp. Normally you would need to authenticate to able to send email. If it is the same server try localhost instead.

Is your smtp.va.com server a different server ? If so, are you sure it supports open relay smtp. Normally you would need to authenticate to able to send email. If it is the same server try localhost instead.

I'm very sorry for the confusion but I'm not not yet live so I'm obliged to use localhost but it doesn't work it seems my problem is authentication. How do I solve this?

I don't think mail() supports authentication. You can use the PHPMailer package. It's easy to use and well documented. You can find it on SourceForge.

I don't think mail() supports authentication. You can use the PHPMailer package. It's easy to use and well documented. You can find it on SourceForge.

I tried your suggestion and took the very first code I laid my eyes on:

<?php
require_once("PHPMailer/class.phpmailer.php");
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->From = "****@****.com";
$mail->AddAddress("****@yahoo.com");

$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}
?>

Output: Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host.

I still seem to be encountering the problem I was having with vanilla mail.

You may need to add:

$mail->SMTPAuth = true;
$mail->Username = "XXX";
$mail->Password = "YYY";

I added the lines, and just to play on the safe side I used my gmail account

<?php
require_once("PHPMailer/class.phpmailer.php");
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->Host = "ssl://smtp.gmail.com:465"; 
$mail->SMTPAuth = true;
$mail->Username = '****@gmail.com';
$mail->Password = "*****";
$mail->From = "*****s@gmail.com";
$mail->AddAddress("*****@yahoo.com");

$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}
?>

Output: It didn't output anything!

I checked my test address at yahoo and no emails were added :(

$mail->Host = "smtp.gmail.com";

and I think

$mail->Port = 465;

But you'll have to check the manual.

still nothing. Any ideas? I'm still open for suggestions

Hi or you could have a go at this one

<?php
function spamcheck($field){
if (eregi("to:",$field) || eregi("cc:",$field))
{	return TRUE;
}else{	
return FALSE;
}
}
if (isset($_REQUEST['email']))
{
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==TRUE){
echo "Invalid input.";
}else{	
$name = $_REQUEST['name'];	
$email = $_REQUEST['email'];	
$subject = $_REQUEST['subject'];	
$message = $_REQUEST['message'];	
mail("email@email", "Subject: $subject", 	
$message, "From: $email"); 		
echo "Thanks. We'll be in touch soon.";
}
}else{
echo 
"<form method='post' action='contact.php'>

Name:
<input type='text' name='name'>
<br />
Email:<input type='text' name='email'>
<br />
Subject:<input type='text' name='subject'><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea>
<br />
<input type='submit' />
</form>";
}
?>

Harrence

I've tried all your suggestions and its still not working. Maybe tomorrow I'll find out what the problem is since I'm going live tomorrow. For the meantime, I'm open for more suggestions.

This problem is harder than I thought :)

Turn on all errors and look what's in the error-log.

Can you advise me as to the methods of how to turn on all errors and point me to the location of the error log. As I would like to point out, I am extremely new to PHP. :icon_question:

It is well documented within the PHP.INI file. All the info your need is there. Just follow the instructions therein.

The error that you are getting may not be exact, there is a whole other error system in class.smtp.php and you can see where the error accumulates around line 1395.

function setError($msg)
{
    $this->error_count++;
    $this->ErrorInfo = $msg;
}

If you can find a way to echo this variable "$this->ErrorInfo" inside class.smtp.php upon failure you will know at what point the smtp class is failing which will give you the exact error message you are looking for.

If you are not live at present, do you have a local server like mamp or zamp?
You can't execute php without a proper server. A browser locally won't do it.

Best harrence.

If you are not live at present, do you have a local server like mamp or zamp?
You can't execute php without a proper server. A browser locally won't do it.

Best harrence.

If you meant a http server, I have Apache 2.2

Are you running all your php files through your apache server?
With MAMP(for mac) or ZAMP(for windows) all your php files
need to come from ht.docs and your local server (MAMP or ZAMP)
must be running. Does your remote server support php?
Apologise if you know all this already. Just trying to get a picture.

H

The error that you are getting may not be exact, there is a whole other error system in class.smtp.php and you can see where the error accumulates around line 1395.

function setError($msg)
{
    $this->error_count++;
    $this->ErrorInfo = $msg;
}

If you can find a way to echo this variable "$this->ErrorInfo" inside class.smtp.php upon failure you will know at what point the smtp class is failing which will give you the exact error message you are looking for.

Unfortunately, I did that.

if(!$mailer->Send())
{
   echo "Message was not sent<br/ >";
   echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
   echo "Message has been sent";
}

Didn't work.

This article has been dead for over six months. Start a new discussion instead.