Results 1 to 4 of 4
Thread: php what?
-
March 4th, 2008, 02:22 PM #1
php what?
Hi
I got this php from a tutorial:
<?php
function form_display($name="", $email="", $website="", $subject="", $message="") {
echo '<form action="contact.php" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Contact Form</legend>
<label for="name">name</label>
<input name="name" id="name" type="text" value="'.$name.'" size="50" maxlength="50" />
<label for="email">e-mail</label>
<input name="email" id="email" type="text" value="'.$email.'" size="50" maxlength="50" />
</fieldset>
<fieldset>
<legend>Message</legend>
<label for="subject">subject</label>
<input name="subject" id="subject" type="text" value="'.$subject.'" size="50" maxlength="50" />
<label for="message">text</label>
<textarea name="message" cols="50" rows="5" id="message"> '.$message.'</textarea>
</fieldset>
<fieldset>
<input class="button" type="submit" name="send" value="Send message" />
</fieldset>
</form>';
}
function validate_form($name, $message, $email) {
if ((empty($name)) || (empty($message)) || (empty($email))) {
echo 'Error! You didn\'t fill all the required fields (name, e-mail and message).';
return false;
} elseif (!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
echo 'Error! You didn\'t enter a valid e-mail address.';
return false;
} else {
return true;
}
}
if(count($_POST) > 0) {
$to = 'franco_tanzarella@yahoo.co.uk';
$name = stripslashes($_POST['name']);
$message = stripslashes($_POST['message']);
$subject = stripslashes($_POST['subject']);
$email = $_POST['email'];
$headers = "From: $name <$email> \r\nReply-To:$email\r\nContent-Type: text/plain; charset=UTF-8\r\nX-Mailer: PHP/".phpversion();
if(validate_form($name, $message, $email)) {
mail($to, $subject, $message, $headers);
} else {
form_display();
}
} else {
form_display();
}
?>
but when I test it on the website I get this error:
Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\Domains\crystal-concept.com\wwwroot\contact.php on line 42
my service provider gave me this piece of code to correct this problem, the only thing is...I don't know a thing about php and I don't know what to change in order for this to work.
Any help?
ini_set("SMTP","mail.host4servers.com");
ini_set("sendmail_from","admin@host4servers.com");
if (mail("support@paradigmsolutions.co.za","This is a test","This is the body","From: user@domain.com\r\nContent-type: text/plain\r\n\r\n"))
{
print "Success";
}
else
{
print "Failed";
}
?>
-
March 4th, 2008, 02:35 PM #2
the script they gave you was to send a test.
becomes:PHP Code:if(validate_form($name, $message, $email)) {
mail($to, $subject, $message, $headers);
} else {
form_display();
}
} else {
form_display();
}
PHP Code:if(validate_form($name, $message, $email)) {
ini_set("SMTP","mail.host4servers.com");
ini_set("sendmail_from","admin@host4servers.com");
#if you want to just send the form on your own without support's help use the line below - if not place a # at the beginning
mail($to, $subject, $message, $headers);
# if you just want to send a test to the support team at your provider - remove the # from the beginning of the following line
#mail("support@paradigmsolutions.co.za","This is a test","This is the body","From: user@domain.com\r\nContent-type: text/plain\r\n\r\n")
} else {
form_display();
}
} else {
form_display();
}
-
March 4th, 2008, 03:21 PM #3
Great it doesn't give me that error message anymore just a blank page so it must have sent the mail. Is there a way I can give it a url to load when its done?
I havent received any emails though but I'll give it a minute or two and check again.
thanx for the help.
-
March 5th, 2008, 06:57 PM #4364The list goes on and on..
postsTry wrapping an if statement around your mail() code.
PHP Code:if( mail($to, $subject, $message, $headers)){
header('Location: http://urlgoeshere.com'); //forward to wherever. NOthing must have been sent to the page already. such as an echo or even any <html> tags
}else{
}
PHP Code:if(validate_form($name, $message, $email)) {
ini_set("SMTP","mail.host4servers.com");
ini_set("sendmail_from","admin@host4servers.com");
#if you want to just send the form on your own without support's help use the line below - if not place a # at the beginning
if( mail($to, $subject, $message, $headers)){
header('Location: http://urlgoeshere.com'); //forward to wherever. NOthing must have been sent to the page already. such as an echo or even any <html> tags
}else{
}
# if you just want to send a test to the support team at your provider - remove the # from the beginning of the following line
#mail("support@paradigmsolutions.co.za","This is a test","This is the body","From: user@domain.com\r\nContent-type: text/plain\r\n\r\n")
} else {
form_display();
}
} else {
form_display();
}

Reply With Quote



Bookmarks