Forum Moderators: coopster
I'm a novice with PHP and I wonder if anyone can point me in the right direction. Does this have to be an HTML problem or could it be something with the script or server configuration? I've spent a couple hours on this to no avail, so any help would be greatly appreciated. For what it's worth I've copied the script below.
<?php
$hsDesc = stripslashes($hsDesc);
$hsFirstName = stripslashes($hsFirstName);
$hsLastName = stripslashes($hsLastName);
require ("http://www.mysite.com/hshead.php");
if (!$hsFirstName ¦¦!$hsLastName ¦¦!$hsPhone)
{
echo "<h1>Oops!</h1>
<p align=\"center\">You didn't enter the necessary contact information.<br><br>
Please press the back button on your browser to return to the form<br>
and fill in your first name, last name and phone number.<br><br>
Thank you!</p>
<img src=\"images/nav/shim.gif\" width=\"125\" height=\"190\" alt=\"\">";
require ("http://www.mysite.com/hsfoot.php");
exit;
}
else {
echo "<h1>Thank You for Your Inquiry!</h1>
<p align=\"center\">A representative from our office will contact you<br> at the phone number or e-mail address you provided.</p>
<img src=\"images/nav/shim.gif\" width=\"125\" height=\"190\" alt=\"\">";
require ("http://www.mysite.com/hsfoot.php");
mail ("email@mysite.com", "Inquiry from Web Site", "\n
NAME: $hsFirstName $hsLastName
PHONE: $hsPhone
EMAIL: $hsEmail
CONTACT PREF: $hscontact
COMMENTS: $hsDesc\n", "From: $hsFirstName $hsLastName<$hsEmail>\nReply-To: $hsEmail");
}
?>
I thought perhaps I simply needed to add authentication to the mail function, but apparently that's not possible. I've been looking around but can't find a clear answer. Do I use sendmail? go to something like PHPMailer (seems like overkill)? Is this obvious and simple to everyone but me? Any pointers greatly appreciated. I'm on a shared server.
(By the way, isn't it odd that my script does work, though slowly, even though they said authentication is now required?)
I'm not aware of any changes to PHP that would affect this simple script. Are you?
<Sure enough their support person told me I was on a new mail system that requires authentication with a valid POP username and password. I asked if he had an example script and he said no, I should know how to do it. I don't.>
If what your support person is saying is accurate, and let's assume for a moment that it is, this is generally an anti-spam technique used by hosting companies. What I think he means is that you need to first authenticate with the POP server before using the SMTP service. This, though, doesn't explain why it ultimately ends up working, but you can give it a shot.
Basically, you'd have to use fsockopen() to make a POP3 connection to the server, log in to it, then close the connection. After this point, you will be able to send mail successfully for X number of minutes.
Open a connect on port 110, then send the following commands:
USER [username]\n
PASS [password]\n
QUIT\n
And that should authenticate you. It's odd, however, that the local server, the server that is running the service, would need to authenticate with itself before allowing itself to send mail. Or perhaps this is why it ends up working anyway after 60 seconds.
I dont think its the PHP version though - works fine on server running 4.2.2 but not on 4.3.3.
Havent had a chance to contact the hosting co yet but I reckon its an authentication issue as I know they use SMTP after POP, strange though that it does work eventually as NickCoons pointed out.