Solved

PHP and Email sent from a Web page on Windows server

Posted on 2011-09-02
4
466 Views
Last Modified: 2013-12-18
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 =======================


0
Comment
Question by:KennethSumerford1
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
Comment Utility
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
 

Assisted Solution

by:KennethSumerford1
KennethSumerford1 earned 0 total points
Comment Utility
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
 

Author Closing Comment

by:KennethSumerford1
Comment Utility
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
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

Featured Post

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Join & Write a Comment

New-MailboxSearch Powershell Command and step by step approach to Search and Extract Emails form Exchange 2013 Journaling server.
This article discusses how to create an extensible mechanism for linked drop downs.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now