0

my website has a contact form in the Contact tab and it is supposed to send the message to an email which I declared in a submit.php file. Unfortunately I do not receive and emails or messages. Is there any way to link the contact form messages to a specific email. The website is eagleview.it

If you need any further code let me know. Thank you so much in advance!

This is the submit.php:

<?php

/* config start */

$emailAddress = 'samkamar@hotmail.com';

/* config end */


require "../php/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);
}

?>
user1165861
  • 829
  • 2
  • 9
  • 14

1 Answers1

0

There seems to be something off about how you're putting together the message. Try using sprintf() like this:

$msg = sprintf("Name : %s <br/> Email : %s <br/>IP : %s <br/><br/> Message : %s"
                , $_POST['name'], $_POST['email'], $_SERVER['REMOTE_ADDR'], nl2br($_POST['message']));
Ayush
  • 41,754
  • 51
  • 164
  • 239
  • O ok...put that in place of this right? 'Name: '.$_POST['name'].'
    Email: '.$_POST['email'].'
    IP: '.$_SERVER['REMOTE_ADDR'].'

    Message:

    '.nl2br($_POST['message']).' ';
    – user1165861 Apr 21 '12 at 03:22