Results 1 to 4 of 4

Thread: php what?

  1. #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";
    }
    ?>

  2. #2
    prstudio's Avatar
    5,107
    posts
    Formerly known as hybrd_dvlpr. This makes life simpler.
    the script they gave you was to send a test.

    PHP Code:
        if(validate_form($name$message$email)) {
            
    mail($to$subject$message$headers);
        } else {
            
    form_display();
        }
    } else {
        
    form_display();

    becomes:

    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();


  3. #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.

  4. #4
    364
    posts
    The list goes on and on..
    Quote Originally Posted by hanzi View Post
    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.
    Try 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();

    "I'm sorry baby I didn't know it was your turn." - Austin Powers

    check out my*[deviantART] art

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012