/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Contact form not working. (copied directly from another site)

Hi there. I copied this contact form script directly from another site which I created (albeit on a different server) and now it isn’t sending the mail. Can anyone see what the problem may be? It’s got me stumped and I don’t really want to have to start from scratch as it was a good script. (plus it took me and the posters on this forum ages to get working!)

[code=php]<?php
if ($_SERVER[‘REQUEST_METHOD’] != ‘POST’){
$me = $_SERVER[‘PHP_SELF’];
?>
<form name=”form1″ action=”contact.php” method=”post”>
<div class=”group”>
<div class=”row”>
<span class=”label”>Full Name*</span><span class=”formw”><input type=”text” size=”25″ name=”name” /></span>
</div>
<div class=”row”>
<span class=”label”>Company*</span><span class=”formw”><input type=”text” size=”25″ name=”company” /></span>
</div>
<div class=”row”>
<span class=”label”>Position</span><span class=”formw”><input type=”text” size=”25″ name=”position” /></span>
</div>
<div class=”row”>
<span class=”label”>Email*</span><span class=”formw”><input type=”text” size=”25″ name=”email” /></span>
</div>
<div class=”row”>
<span class=”label”>Contact Number*</span><span class=”formw”><input type=”text” size=”25″ name=”number” /></span>
</div>
<div class=”row”>
<span class=”label”>Comments, feedback or nature of enquiry*</span><span class=”formw”>
<textarea cols=”25″ rows=”8″ name=”comments”></textarea></span>
</div>
<div class=”row”>
<span class=”label”>Tick this box if you would like to join the Skills Exchange mailing list</span><span class=”formw”><input type=”checkbox” size=”25″ name=”list” /></span>
</div>
<div class=”row”>
<span class=”formw”><input type=”submit” name=”Submit” value=”Send”></span>
</div>
<div class=”spacer”>
&nbsp;
</div>
</div>
</form>
<p>* marks required fields</p>
<?php
} else {
error_reporting(0);
$errors = array();
$page = $_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’];
if (!session_is_registered(“SESSION”)){
$errors[] = “Invalid form submission”;
}
if (!$_POST[‘name’])
$errors[] = “Name is required”;
if (!$_POST[’email’])
$errors[] = “Email Address is required”;
if (!$_POST[‘company’])
$errors[] = “Company is required”;
if (!$_POST[‘number’])
$errors[] = “Contact number is required”;
if (!$_POST[‘comments’])
$errors[] = “Message body is required”;
if (count($errors)>0){
echo “<h2>ERROR:</h2>n”;
foreach($errors as $err)
echo “<p>$err</p>n”;
} else {

$to = “[email protected]”;
$name = stripslashes($_POST[‘name’]);
$email = stripslashes($_POST[’email’]);
$comments = stripslashes($_POST[‘comments’]);
$company = stripslashes($_POST[‘company’]);
$position = stripslashes($_POST[‘position’]);
$number = stripslashes($_POST[‘number’]);
$list = stripslashes($_POST[‘list’]);
$msg = ”
<p><b>Name:</b> t$name<br />n
<b>Company:</b> t$company<br />n
<b>Position:</b> t$position<br />n
<b>Email:</b> t$email<br />n
<b>Contact number:</b> t$number<br />n
<b>Comments:</b> t$comments<br />n
<b>Mailing List:</b> t$list<br /></p>n”;

$msg1 = “<html>n
<head>n
<title>Contact/Feedback form</title>n
</head>n
<body>n
<h3>Contact/Feedback form</h3>n
$msg
</body>n
</html>n”;

$subject = “Online conatct form”;
$headers = ‘MIME-Version: 1.0’ . “rn”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “rn”;

if (mail($to, $subject, $msg1, $headers, ‘[email protected]’))
echo (“<h3>Your message has been sent</h3>n
<p>We will endeavour to reply to you as soon as possible</p>
$msg”);
else
echo “<h3>Message failed to send</h3>n
<p>Please try again later or contact Hamishn
by using one of the other methods of contact listedn
on this page.</p>”;
}
}
?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DoppleauthorJun 12.2006 — It was to do with the fact that it's hosted on Supremecenter and that yo can only send emails to addresses hosted on that server.
Copy linkTweet thisAlerts:
@DoppleauthorJun 13.2006 — Ok, sorry, I though creating a test email account on the server would resolve this but it hasn't. I did however try a script which has worked. I have posted this below. Can anyone see why one would work and another would not? I assume it is to do with the server settings but, pardon my ignorance, I cannot tell.
[code=php]<?php

// Add as many Names/ Departments -- e-mail addresses as you want here
$eMail[] = array( 'Information', '[email protected]' );

// Handle older versions of PHP
if( ! isset( $_POST ) ) $_POST = &$HTTP_POST_VARS;
if( ! isset( $_SERVER) ) $_SERVER = &$HTTP_SERVER_VARS;

?>
<HTML>
<HEAD>
<TITLE>Mail Me!</TITLE>
</HEAD>
<BODY>

<?php if( ! isset( $_POST["EMail"] ) ) { ?>

<form method="POST" name="MailForm">
<div align="center">
<center>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td valign="top" align="right">To:</td>
<td>

<?php

// Display Menu if More than one name
if( count( $eMail ) > 1 ) {
echo "<select size="1" name="To">n";

foreach( $eMail as $k => $a )
echo "<option value="$k">$a[0]</option>n";
echo "</select>n";
} else
echo $eMail[0][0];

?>
</td>
</tr>
<tr>
<td valign="top" align="right">From:</td>
<td><input type="text" name="From" size="44" maxlength="32"></td>
</tr>
<tr>
<td valign="top" align="right">E-Mail:</td>
<td><input type="text" name="EMail" size="44"></td>
</tr>
<tr>
<td valign="top" align="right">Subject: </td>
<td>
<p align="center"><input type="text" name="Subject" size="44"></td>
</tr>
</table>
</center>
</div>
<p align="center"><textarea rows="10" name="Body" cols="45"></textarea></p>
<p align="center"><input type="submit" value="Send" name="B1"></p>
</form>

<?php
} else {

echo "<B>Attempting to send message</b></BR></BR>n";

$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

if( count( $eMail ) == 1 )
$_POST["To"] = "0";

if( mail( '"' . $eMail[$_POST["To"]][0] . '" <' . $eMail[$_POST["To"]][1] . '>',
$_POST["Subject"], $_POST["Body"],
'Return-Path: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">n"
. 'From: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">n"
. 'Reply-To: "' . $_POST["From"] . '" <' . $_POST["EMail"] . ">n"
. "X-Mailer: PHP/" . phpversion() . "n"
. "X-From-IP: " . $userip ) )
echo "Message Sent Successfully";
else
echo "UNABLE To Send Message.";
}
?>
</BODY>
</HTML>[/code]
×

Success!

Help @Dopple spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...