Feedback form not sending email php

philo694

New Member
Messages
6
Reaction score
0
Points
0
Hi
When I run my contact email form it returns the message "Error!"
The code was ripped rom another post so appologies to the original writer!
I do not know why? Can anyone help!

Code for Form is:

<form id="form1" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Email
<span class="small">Enter a Valid Email</span>
</label>
<input type="text" name="email">
<br />
<br />
<br />
<br />
<label>Message
<span class="small">Type Your Message</span>
</label>
<textarea name="message" rows="6" cols="25"></textarea><br />

<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>

</form>

php code is:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "philo694@softairtest.x10.mx";
$subject = "Contact Form";
$mailheader = "From: philo694@softairtest.x10.mx\r\n";
echo "recipient: $recipient <br />";
echo "subject: $subject <br />";
echo "formcontent: $formcontent <br />";
echo "mailheader: $mailheader <br />";

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You for contacting me!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>



Thanks in advance
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.

[URL=http://www.phpfreaks.com/blog/or-die-must-die]Don't use [c]die[/c][/URL] when outputting HTML. You'll get invalid HTML.

[URL="http://x10hosting.com/forums/news-announcements/178721-boru-upgrade.html"]Boru's been undergoing maintenance[/URL], if that's your server. There's a post about it in the [URL="http://x10hosting.com/forums/news-announcements/"]News and Announcements[/URL] section; it's always good to check in there periodically, and whenever something that worked previously no longer does.
 

philo694

New Member
Messages
6
Reaction score
0
Points
0
Thanks for the comments guys. Now does anyone know why my script is erroring?
Please help! I need to fix this today if possible.
 

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Are you on Boru? If so, it's being upgraded and so some services and intemittently turned off. Sorry
Edit: Oops, had never heard of Fris before...

---------- Post added at 09:43 PM ---------- Previous post was at 09:13 PM ----------

Where you do you enter your username (that is, philo964+philo964.x10.mx)? How about your port (25)? Are you using PHPMailer? Can we see the mail function? Because I want to make sure you actually have a mail function and that you are using it properly. You also aren't allowed more than 100 emails per day, or forged headers (but I see that you are not using a forged header).

A few helpful but not nessecary tips:
Because you are most likely ever sending from philo964, you shouldn't rely on a changing variable to assign it. Instead, build it into the function. It's a lot easier. Example of a function (using PHPMailer, because that's most commonly used) that I have tweaked time and time again to be perfect. Just set your own email. For usage, set $to to the recipent, $subject to the subject, $message to the message to send (not in HTML, but you can tweak it to do that if you want to) and $winerror or $failerror being what to report to the user if you win (the message was sent successfully) or fail (the opposite). You must follow the instructions in the comments for it to work:

<?php
@mysql_connect("localhost", "philo964_username", "enter your password here") or die("Could not connect: ".mysql_error() ); // tweak to connect to MySQL and keep track of email limit
@mysql_select_db("philo964_databasename") or die("Could not select db: ".mysql_error() ); // tweak to connect to db
require_once("phpmailer/class.phpmailer.php"); // set this to the path of the class.phpmailer file, and remove this comment
function smtpmailer($to, $subject, $message, $winerror, $failerror) {
$mltimestring = date("Y z G");
$findmaillimit = mysql_query("SELECT * FROM maillimit LIMIT 0, 1"); // create a table in your db called maillimit. Make the structure contain a varchar and an integer, time and limit.
$ismaillimittrue = mysql_fetch_row($findmaillimit);
if (!$ismaillimittrue) {
mysql_query("INSERT INTO maillimit (time, limit) VALUES ('" + mysql_real_escape_string($mltimestring) + "', 0)");
$findmaillimit = mysql_query("SELECT * FROM maillimit LIMIT 0, 1");
$ismaillimittrue = mysql_fetch_row($findmaillimit);
}
if ($ismaillimittrue[1] < 100 || $ismaillimittrue[0] != $mltimestring) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Username = "philo964+softairtest.x10.mx"; // I made it just for you
$mail->Password = "enter your password here";
$mail->Host = "mail.softairtest.x10.mx"; // just for you again
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->SetFrom("philo964@softairtest.x10.mx", "Philo964 at Soft Air Test");
$mail->AddAddress($to);
$mail->AddReplyTo("philo964@softairtest.x10.mx", "Philo964 at Soft Air Test");
$mail->Subject = $subject;
$mail->Body = $message;
$mail->SMTPDebug = 0; // if you get an error, set this higher for more details
if(!$mail->Send()) {
echo $failerror;
// you fail
} else {
echo $winerror;
// you win (remove these comments if you understand)
}
if ($ismaillimittrue[0] == $mltimestring) {
mysql_query("UPDATE maillimit SET time='" + mysql_real_escape_string($ismaillimittrue[0]) + "', limit=" + ($ismaillimittrue[1] + 1) + " LIMIT 1");
} else {
mysql_query("UPDATE maillimit SET time='" + mysql_real_escape_string($mltimestring) + "', limit=0 LIMIT 1");
} // this is important. It updates the maillimit table to cehck you aren't over.
} else {
echo $failerror;
// you are over your mail limit!
}
}
?>
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.[/QUOTE]


[quote="ellescuba27, post: 885398"]Where you do you enter your username (that is, philo964+philo964.x10.mx)? How about your port (25)?[/QUOTE]
[c]mail[/c] hands off the message to sendmail for delivery, rather than opening an SMTP (or other mail delivery protocol) session itself, so it doesn't support or require authentication.

[quote="ellescuba27, post: 885398"]Are you using PHPMailer? Can we see the mail function? Because I want to make sure you actually have a mail function and that you are using it properly.[/QUOTE]
[URL="http://php.net/mail"][c]mail()[/c][/URL] is a core PHP extension.


[quote="ellescuba27, post: 885398"]
Because you are most likely ever sending from philo964, you shouldn't rely on a changing variable to assign it. Instead, build it into the function. It's a lot easier.[/QUOTE]
On the contrary, using a variable properly abstracts out data from code, reducing repetition. Variables don't change unless you code an assignment statement, so there's no real danger. Variables should be safely ensconced in some sort of scope or namespace (either actual [URL="http://php.net/namespace"]namespaces[/URL] or a class or instance property), so the chance of accidental assignment due to name collision is reduced to nil.

The [URL="http://x10hosting.com/forums/programming-help/162529-php-begin-deprecation-ext-mysql-start-moving-your-development-pdo-now.html"]mysql extension[/URL] is outdated and on its way to deprecation. Instead, use PDO, which has many useful improvements, such as [URL=http://www.php.net/PDO.prepared-statements]prepared statements[/URL] and support for the [url=http://php.net/Traversable]Traversable[/url] interface, so you can loop over results with [c]foreach[/c].

[URL="http://stackoverflow.com/questions/321299/"]Don't use [FONT="Courier New"]SELECT *[/FONT][/URL] unless you're writing a DB administration program; select only the columns you need.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I tried your code on Chopin, and it works there.

Some things:
1) sent to a recipient on gmail, and he recieved it
2) sent to itself and it worked, but that account has the MX entries set to a Google Apps account, not the x10 account. Not sure if having the "from" and "recipient" being exactly the same could be the problem. Have you tried sending it to an outside account?
3) Boru was being worked on. Not sure if that is done. Do you still have the problem?
 

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Oh yeah, I had almost completley forgot about mail()! I don't use it because on Linux it opens a new window, and I prefer to use SMTP (similar to Windows)
 

philo694

New Member
Messages
6
Reaction score
0
Points
0
Hi All
Thanks for all the replies. I am still having the issues but it seems they are working on the server my site is on so I now have to suffer because of their inability to setup a server. I'll leave the site as it is for a few weeks and check again. :rolleyes:
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
So. Where did you find the error in the script he posted?
The ability to find (and fix) bugs doesn't imply bugs exist in any given script.

The guy clearly has issues.
My issue is that you come here asking for help, then denigrate the server admins by making a statement about their abilities when you don't appear to be that knowledgable; hence, you're judging in ignorance. They don't owe you anything. You're note even paying for hosting.
 
Last edited:
Top