Jump to content

php mail not sending!?


MSUK1

Recommended Posts

I have found it a bit strange recently how i stopped receiving online emails from my website, we havnt changed the code as far as i am aware. but for some reason neither the user or staff receives an email

 

the code below is our process for the mail.

 

please could somebody advise why?

 

<?php

$host="localhost"; // Host name 
$username="HIDDEN"; // Mysql username 
$password="HIDDEN"; // Mysql password 
$db_name="HIDEEN"; // Database name 
$tbl_name="HIDDEN"; // Table name

$name = $_POST['name'];
$email = $_POST['email'];
$web = $_POST['web'];
$tel = $_POST['tel'];
$sub = $_POST['sub']; 
$message = $_POST['message']; 
$ip = $_SERVER['REMOTE_ADDR'];
$datetime=date("d-m-y"); //date time


// validation

function is_valid_email($email) {
  return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}

if (!is_valid_email($email)) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error\">";
  exit;
}

$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($tel)=="") $validationOK=false;
if (Trim($sub)=="") $validationOK=false;
if (Trim($message)=="") $validationOK=false;
if (!$validationOK) {

  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error\">";

  exit;

}
$EmailFrom = Trim(stripslashes($_POST['email'])); 
$EmailTo = "info@msukgroup.co";
$Subject2 = Trim(stripslashes($_POST['sub'])); 
$Name = Trim(stripslashes($_POST['name'])); 
$Comments = Trim(stripslashes($_POST['message'])); 
$Subject = "MSUKGroup - Thankyou For Contacting ";

// STAFF EMAIL

$staffmail = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MSUKGroup</title>
<style>
p {
margin-top:0;
margin-bottom:4px;
}
</style>
</head>

<body style="color: #666666; font-size:small; font-family:Franklin Gothic Book">

<table style="width: 516px; height: 42px;" cellspacing="0" cellpadding="0">
			<!-- MSTableType="layout" -->
			<tr>
							<td valign="top" style="height: 42px; width: 516px">
							<table style="width: 500px; height: 42px;" cellspacing="0" cellpadding="0">
											<!-- MSTableType="layout" -->
											<tr>
															<td valign="top" style="height: 42px; width: 500px">
															<img src="http://msukgroup.co/img/logos/orange.png" width="323" height="42" /></td>
											</tr>
							</table>
							</td>
			</tr>
</table>

							<p>Dear  ' . $name . ',</p>
<p>Thankyou for contacting the MSUKGroup via our online submission form. A 
relevant representative will be with you within 24 hours to assist you further 
with your query. </p>
<p>Here is what we gathered from your query:</p>
<table style="width: 100%" cellspacing="4" cellpadding="0">
			<tr>
							<td style="width: 60px" align="right"><strong>
							Name:</strong></td>
							<td> ' . $name . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Email:</strong></td>
							<td> ' . $email . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Website:</strong></td>
							<td> ' . $web . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Tel:</strong></td>
							<td> ' . $tel . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Subject:</strong></td>
							<td> ' . $sub . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Message:</strong></td>
							<td> ' . $message . '</td>
			</tr>
</table>

							<p>In the meantime, if you have any unanswered 
							questions please take a look around our website 
							and you&#39;ll find out more about  our group 
							and services.</p>
<p><img src="http://msukgroup.co/img/logo3.png" width="129" height="21" /></p>
<p>Hosting - Designs - eCommerce - Solutions - Events and more...</p>
<p><strong>Web:<br />
</strong><a href="http://www.msukgroup.co"><span style="color:#FF7800">http://www.msukgroup.co</span></a></p>
<p><strong>Email:<br />
</strong><a href="http://www.msukgroup.co"><span style="color:#FF7800">
info@msukgroup.co</span></a></p>

							</body>

</html>
';

// USER EMAIL

$usermail = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MSUKGroup</title>
<style>
p {
margin-top:0;
margin-bottom:4px;
}
</style>
</head>

<body style="color: #666666; font-size:small; font-family:Franklin Gothic Book">

<table style="width: 516px; height: 42px;" cellspacing="0" cellpadding="0">
			<!-- MSTableType="layout" -->
			<tr>
							<td valign="top" style="height: 42px; width: 516px">
							<table style="width: 500px; height: 42px;" cellspacing="0" cellpadding="0">
											<!-- MSTableType="layout" -->
											<tr>
															<td valign="top" style="height: 42px; width: 500px">
															<img src="http://msukgroup.co/img/logos/orange.png" width="323" height="42" /></td>
											</tr>
							</table>
							</td>
			</tr>
</table>

							<p>Hello Admin,</p>
<p>' . $name . ' has sent a message using the contact form on the site.<br>
<strong>Date Message Sent: ' . $datetime . ' <br>
IP Address: ' . $ip . ' </strong><br>
</p>
<p>Here is what we gathered from their query:</p>
<table style="width: 100%" cellspacing="4" cellpadding="0">
			<tr>
							<td style="width: 60px" align="right"><strong>
							Name:</strong></td>
							<td> ' . $name . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Email:</strong></td>
							<td> ' . $email . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Website:</strong></td>
							<td> ' . $web . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Tel:</strong></td>
							<td> ' . $tel . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Subject:</strong></td>
							<td> ' . $sub . '</td>
			</tr>
			<tr>
							<td style="width: 60px" align="right"><strong>
							Message:</strong></td>
							<td> ' . $message . '</td>
			</tr>
</table>

							<p>He has been notified of a 24 hour wait so 
							please respond within this time frame.</p>
<p><img src="http://msukgroup.co/img/logo3.png" width="129" height="21" /></p>
<p>Hosting - Designs - eCommerce - Solutions - Events and more...</p>
<p><strong>Web:<br />
</strong><a title="MSUKGroup" href="http://www.msukgroup.co"><span style="color:#FF7800">http://www.msukgroup.co</span></a></p>
<p><strong>Email:<br />
</strong><a href="http://www.msukgroup.co"><span style="color:#FF7800">
info@msukgroup.co</span></a></p>

							</body>

</html>
';


// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: DO NOT REPLY - MSUKGroup <noreply@msukgroup.co>' . "\r\n";

// Mail it
mail($EmailTo, $Subject2, $usermail, $headers);
mail($EmailFrom, $Subject2, $staffmail, $headers);


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name(name, email, web, tel, sub, message, date, ip)VALUES('$name', '$email', '$web', '$tel', '$sub', '$message', '$datetime', '$ip')";
$result=mysql_query($sql);

//check if query successful 
if($result){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=successful\">";
}

else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error\">";
}

mysql_close();
?>

 

 

Link to comment
Share on other sites

if their was an error at the email stage it shouldnt work at all!

 

What makes you think that ^^^. Your code is not even testing the value that the mail() function call returns (which would tell you only if your sending mail server accepted the email, not if it was actually sent.)

Link to comment
Share on other sites

because usually if theirs an error on line 74, php stops executes upto that line error?

 

the database function is after mail, theirfore if their was an error at the mail process the data shouldnt be getting submitted to the DB?

 

excuse my ignorance if im wrong :)

 

can you advise what i can do to test this then?

Link to comment
Share on other sites

because usually if theirs an error on line 74, php stops executes upto that line error?

 

^^^ Only on fatal runtime errors (or fatal parse errors inside included files) otherwise php continues execution through to the end of your file or until it reaches an exit/die statement in your code. Function calls simply return execution to the calling code and the code continues running. It is up to you to put logic into your program to test the result of a function call.

 

the database function is after mail, theirfore if their was an error at the mail process the data shouldnt be getting submitted to the DB?

 

^^^ Only if you put logic in your code to do it that that way.

 

can you advise what i can do to test this then?

 

The mail() function call returns either a TRUE or a FALSE value. You would test that value using an if(){}else{} statement.

Link to comment
Share on other sites

ok i get that now,

 

i have done this:

 

// Mail it

$mail1 = "$EmailTo, $Subject2, $usermail, $headers";
$mail2 = "$EmailFrom, $Subject2, $staffmail, $headers";

$sent = mail($mail1);
$sent2 = mail($mail2);

if($mail1){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=successful\">";
}

else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error1\">";
}

if($mail2){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=successful\">";
}

else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error2\">";
}

 

i get this error, then it returns me to successful:

 

Warning: mail() expects at least 3 parameters, 1 given in /home/msuk/public_html/Contact/x2ig9gedfgndfjgnd034iug39igergb.php on line 240

Link to comment
Share on other sites

realised what the mistake was their, here is what ive updated to:

 

// Mail it

if(mail($EmailTo, $Subject2, $usermail, $headers)){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=successful\">";
}

else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error1\">";
}

if(mail($EmailFrom, $Subject2, $staffmail, $headers)){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=successful\">";
}

else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../Contact/?sent=error2\">";
}

 

still not sending?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.