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 = '[email protected]';
$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
https://forums.phpfreaks.com/topic/159228-solved-still-not-sending-on-submit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.