Jump to content

[SOLVED] Still not sending on Submit


Recommended Posts

I've debugged it, the mail variables are defined values. Ive echo'd it and it says it is sending. The mail() works on my server. The e-mail account is working as it can recieve mail from other sources. SMTP is activated on my hosting account. I cannot see why this doesn't work, my hosts are not viable to help me with my script troubles. Please, someome tell me why this still isnt sending mail on submit. It has worked on another server, but there must be a reason as to why it isnt working on mine..

 

<?php
# PHP Copyright 2007, Thomas Boutell and Boutell.Com, Inc.
# Edited by Definition Designs.

$recipient = 'information@definition-designs.co.uk';
$serverName = 'www.definition-designs.co.uk';

if ($_POST['send']) {
sendMail();
} elseif (($_POST['cancel']) || ($_POST['continue'])) {
redirect();
} else {
displayForm(false);
}

function displayForm($messages)
{
global $login;
$escapedEmail = htmlspecialchars($_POST['email']);
$escapedRealName = htmlspecialchars($_POST['realname']);
$escapedSubject = htmlspecialchars($_POST['subject']);
$escapedBody = htmlspecialchars($_POST['body']);
$returnUrl = $_POST['returnurl'];
if (!strlen($returnUrl)) {
	$returnUrl = $_SERVER['HTTP_REFERER'];
	if (!strlen($returnUrl)) {
		$returnUrl = '/';
	}
}
$escapedReturnUrl = htmlspecialchars($returnUrl);
?>
<html>
<head>
<title>Definition Designs - Web and Graphics Design</title>
<meta name="Author" content="Joshua Martin" /> 
<meta name="Description" content="Definition Designs is the website of Web and Graphic Designer Joshua Martin" />

<div id="MailForm">

<?php
if (count($messages) > 0) {
	$message = implode("<br>\n", $messages);
	echo("<h3>$message</h3>\n");
}
?>
<form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>">
<p>
<b>Your</b> Email Address   
<input 
name="email" 
size="35" 
maxlength="35" 
value="<?php echo $escapedEmail?>"/>
</p>
<p>
Your <b>Real</b> Name    
<input
name="realname" 
size="35" 
maxlength="35" 
value="<?php echo $escapedRealName?>"/>

</p>
<p>
Subject Of Your Message   
<input 
name="subject" 
size="35" 
maxlength="35"
value="<?php echo $escapedSubject?>"/> 

</p>
<p>
<i>Please enter the text of your message in the field that follows.</i>
</p>
<textarea 
name="body" 
rows="10" 
cols="60"><?php echo $escapedBody?></textarea>
<p>
<input type="submit" name="send" value="Send Your Message"/>
<input type="submit" name="cancel" value="Cancel - Never Mind"/>
</p>
<input 
type="hidden"
name="returnurl" 
value="<?php echo $escapedReturnUrl?>"/>
</form>
</body>
</html>
<?php
}

function redirect()
{
global $serverName;
$returnUrl = $_POST['returnurl'];	
$prefix = "http://$serverName/";
if (!beginsWith($returnUrl, $prefix)) {
	$returnUrl = "http://$serverName/"; 
}
header("Location: $returnUrl");
}

function beginsWith($s, $prefix)
{
return (substr($s, 0, strlen($prefix)) === $prefix);
}

function sendMail()
{
global $recipient;

$messages = array();
$email = $_POST['email'];
if (!preg_match("/^[\w\+\-\.\~]+\@[\-\w\.\!]+$/", $email)) {
	$messages[] = "That is not a valid email address. Perhaps you left out the @something.com part?
	";
}
$realName = $_POST['realname'];
if (!preg_match("/^[\w\ \+\-\'\"]+$/", $realName)) {
	$messages[] = "The real name field must contain only alphabetical characters, numbers, spaces, and the + and - signs. We apologize for any inconvenience.


	";
}
$subject = $_POST['subject'];
if (preg_match('/^\s*$/', $subject)) {
	$messages[] = "Please specify a subject for your message.


	";
}
$body = $_POST['body'];
        if (preg_match('/^\s*$/', $body)) {
	$messages[] = "Your message was blank. Did you mean to say something? Click the Cancel button if you do not wish to send a message.


	";
}
   if (count($messages)) {
	displayForm($messages);
	return;
}	
mail($recipient, 
	 $subject, 
	 $body) or die("unable to send the mail!");

$escapedReturnUrl = htmlspecialchars($_POST['returnurl']);
?>

<html>
<head>

<title>Definition Designs - Thank You</title>

<link href="/stylesheet.css" rel="stylesheet" type="text/css"/>

</head>

<body>
<div id="phpform">
<h1>Thank You</h1>
<p>
Thank you for contacting us! Your message has been sent. 
</p>
<form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>">
<input type="submit" name="continue" value="Click Here To Continue"/>
<input 
type="hidden"
name="returnurl" 
value="<?php echo $escapedReturnUrl?>"/>
</form>

<?php
}
?>
</body>
</html>

Link to comment
Share on other sites

Try any one (or all three) of these ini-sets:

 

$your_site = "site.com"; //change this

ini_set("SMTP","mail.".$your_site.".com");
ini_set("smtp_port","25");
ini_set("sendmail_from", "info@".$your_site.".com");

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.