...

View Full Version : Emails Not Sending



kamaro
04-22-2012, 09:40 PM
Hi, my contact form does not send the messages to a certain email as it is supposed to. I have all the files and the right paths which connect them all and I am running PHP V5 on my server but it still doesn't work. My website is eagleview.it and if you go to the contact tab and under the source click the submit.php file you can see a error message for what seems to be the wrong file path but everything is actually right. This is what the submit.php file is supposed to be:


<?php

/* config start */

$emailAddress = 'xxxxx@hotmail.com';

/* config end */


require "class.phpmailer.php";

session_name("fancyform");
session_start();


foreach($_POST as $k=>$v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k]=stripslashes($_POST[$k]);

$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


$err = array();

if(!checkLen('name'))
$err[]='The name field is too short or empty!';

if(!checkLen('email'))
$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
$err[]='Your email is not valid!';

if(!checkLen('subject'))
$err[]='You have not selected a subject!';

if(!checkLen('message'))
$err[]='The message field is too short or empty!';

if((int)$_POST['captcha'] != $_SESSION['expect'])
$err[]='The captcha code is wrong!';


if(count($err))
{
if($_POST['ajax'])
{
echo '-1';
}

else if($_SERVER['HTTP_REFERER'])
{
$_SESSION['errStr'] = implode('<br />',$err);
$_SESSION['post']=$_POST;

header('Location: '.$_SERVER['HTTP_REFERER']);
}

exit;
}


$msg=
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />

Message:<br /><br />

'.nl2br($_POST['message']).'

';


$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";

$mail->MsgHTML($msg);

$mail->Send();


unset($_SESSION['post']);

if($_POST['ajax'])
{
echo '1';
}
else
{
$_SESSION['sent']=1;

if($_SERVER['HTTP_REFERER'])
header('Location: '.$_SERVER['HTTP_REFERER']);

exit;
}

function checkLen($str,$len=2)
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}

function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}

?>


Any suggestions on how to fix this? Thanks!

mlseim
04-22-2012, 10:25 PM
It looks like you disabled right-click (using javascripting) so we can't view the HTML source.
I'm not taking the time to turn off my javascripting so I can see your HTML ... sorry.

tangoforce
04-22-2012, 10:55 PM
I'm not taking the time to turn off my javascripting so I can see your HTML ... sorry.

Yet you frequently expect people to take their time trying to understand your php code that isn't highlighted because you refuse to take the time to use the [php] tags!

Pot, Kettle? :D

mlseim
04-22-2012, 11:33 PM
Sorry ...
I promise not to post any more PHP scripts on this forum in the future ... my bad.


.

tangoforce
04-22-2012, 11:36 PM
Sheesh I was only messing about..

tangoforce
04-22-2012, 11:39 PM
@kamaro: Your use of $mail->send(); returns a boolean. Therefore you should at least be testing it like this:



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

mlseim
04-23-2012, 03:04 AM
@tango ...
I know .. I figured you were just kidding ...

It's just bad timing, that's all.

You didn't know that I have been PM'd in the past couple of months
with comments that some of the scripting I've been posting is inefficient,
and not secure. So I'm a bit nervous about posting things. My goal is to
help out, and I always mention that I'm not a "professional programmer",
which is certainly the case. I try not to take this stuff too seriously, but
it seems others on here do this for a professional career, and I'm just
"setting them back" ... correcting my mistakes is wasting their time.

tangoforce
04-23-2012, 03:43 AM
mlseim - PM me when you get a chance, not really the best of places to let out your emotions in this thread. PM me we'll chat.

Tango



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum