PHP and Email sent from a Web page on Windows server

I have tried to send Email from a page at Go Daddy.  My page is in PHP and the Web site is running under Windows.  I tried for at least 2 hours with the regular mail function but it did Not work for me.  I then tried PhpMailer but still get this error:  SMTP server response: 503 RCPT .  Below is most of the code that I used.

function fnSendEmailPhpMailer($toEmail2, $fromEmail2, $subjectEmail2, $message2, &$ErrMsg3, $FirstName2="", $LastName2="", $CCopy2="", $BCopy2="" ) {
      // Use PhpMailer to Send Email from the Web page to a person.
      
      try
      {
            //  $to2 = $toEmail ;
            $message2 = wordwrap($message2, 68) ;
            
            //  Our basic example on the PHPMailer website now is: [2011-09]

require_once('../class.phpmailer.php');
include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

 // $body = file_get_contents('contents.html');
 // $body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.KennethSumerford.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
 
$mail->Port = 25; // alternate is "26" - set the SMTP port for the HOTMAIL server
$mail->Username = "S3@KennethSumerford.com"; //  
$mail->Password = "xxxx"; // HOTMAIL password or other password
 [Password was changed to x's in this post.]

$mail->SetFrom('S3@KennethSumerford.com', 'Kenneth Sumerford');

//  $mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->AddReplyTo('S3@KennethSumerford.com', 'Kenneth Sumerford');

 // $mail->Subject = "PHPMailer Test Subject via smtp (Hotmail), basic";
 $mail->Subject = $subjectEmail2 ;

// $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

 // $mail->MsgHTML($body);
 $mail->MsgHTML( $message2);

$address = $toEmail2;
 //  $mail->AddAddress($address, "John Doe");
 $NameFull2 = $FirstName2 . " " . $LastName2 ;
 $mail->AddAddress($address, $NameFull2);
 $mail->AddCC( $CCopy2, 'Kenneth Sumerford');
 if (strlen($BCopy2) > 4) {
       $mail->AddBCC( $BCopy2, 'SMS inquiry');
 }

// $mail->AddAttachment("images/phpmailer.gif"); // attachment
// $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo "Message sent";
}

  return true ; // <==///========
}  //======== end of try =========
catch ( Exception $e3 )
      {
            $ErrMsg3 = $e3 ;
            return false ; // <==///========
      }                        
      
} //=== fnSendEmailPhpMailer =======================


KennethSumerford1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
You can not send thru any SMTP server but Godaddy's from a web page on their servers.  This is my email demo that works perfectly on IIS7 on Godaddy.  Save as 'Email.php' and put in your email address and try it.
<?php
error_reporting(E_ALL);

# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
    $announce="---";
}
else {
  $toText="your@email.com";
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: \r\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	$mstatus = mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
<!-- 
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
-->
</style>
<script type="text/javascript">
<!--
function check()
{
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    {
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    submitOK="false"
    //return false;
    }
if (nam.length < 5)
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (submitOK=="false")
    {
    alert(alerttxt);
    return false;
    }

}

// -->
</script>
</head>

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

<?php
if ($send != "") {
   	echo ("Send status = $mstatus<br>To: ".$toText."<br>\nSubject: ".$subjectText."<br>\n".$msgText."<br>\ncc: ".$header);
		}
?>

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<!--   <form method="POST" action="<?php echo($PHP_SELF)?>"> -->
  <form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  </form>
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

</font>
</td></tr>
</table> 
</div>

</body>
</html>

Open in new window

0
 
KennethSumerford1Connect With a Mentor Author Commented:
I tried it and it did not work, even though it gave a message of "Your Message has been Sent!"
I tried it the second time and same result, no Email was sent within 5 minutes.  It might turn up later in my Email box but probably not.  

The 2 Emails did turn up in the Spam folder.  I do not understand why but it seems to work.

Thanks!  I worked at least 4 hours on this problem to no avail.
0
 
KennethSumerford1Author Commented:
This solves a very big problem.  I needed to send Email from a Web page on my site, tried at least 4 hours, and failed.   A large number of people using Go Daddy hosting and PHP for sending Email probably have this same problem.

The solution came quickly.  Job well done!

  ----Kenneth Sumerford, Texas
0
 
Dave BaldwinFixer of ProblemsCommented:
The first time I tried this, it took 4 hours for the email to show up.  I had this code running on other web servers including IIS and Apache so I knew it wasn't totally wrong.  And it turns out the info is in the Godaddy help pages, it just isn't easy to find.

Glad to help.
0
All Courses

From novice to tech pro — start learning today.