Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question PHP Contact Form issue - please help!

    Hi there,

    I adjusted a contact form which I downloaded but it keeps giving me an error and does not seem to be sending from my remote server but trying to find a 3rd party server - is there anyone who can help me find the error, please?

    Also, I need to add a tickbox to send copy to sender - any suggestions?

    Error received:
    Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\hosting\10168326\html\contact-Form.php on line 51

    PHP coding:
    <?php

    // Set email variables
    $email_to = 'name@mail.net';
    $email_subject = 'Web Feedback';


    // Set required fields
    $required_fields = array('fullname','email','comment');

    // set error messages
    $error_messages = array(
    'fullname' => 'Please enter a Name to proceed.',
    'email' => 'Please enter a valid Email Address to continue.',
    'comment' => 'Please enter your Message to continue.'
    );

    // Set form status
    $form_complete = FALSE;

    // configure validation array
    $validation = array();

    // check form submittal
    if(!empty($_POST)) {
    // Sanitise POST array
    foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));

    // Loop into required fields and make sure they match our needs
    foreach($required_fields as $field) {
    // the field has been submitted?
    if(!array_key_exists($field, $_POST)) array_push($validation, $field);

    // check there is information in the field?
    if($_POST[$field] == '') array_push($validation, $field);

    // validate the email address supplied
    if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
    }

    // basic validation result
    if(count($validation) == 0) {
    // Prepare our content string
    $email_content = 'New Website Comment: ' . "\n\n";

    // simple email content
    foreach($_POST as $key => $value) {
    if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
    }

    // if validation passed ok then send the email
    mail($email_to, $email_subject, $email_content);

    // Update form switch
    $form_complete = TRUE;
    }
    }

    function validate_email_address($email = FALSE) {
    return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
    }

    function remove_email_injection($field = FALSE) {
    return (str_replace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
    }

    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The error is in how you have SMTP configured to work with your PHP install. Fix that and your mail() function will work.

  • Users who have thanked Fumigator for this post:

    Joycie (12-17-2012)

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Also
    Note:

    When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
    Have you configured the From header in php.ini?
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Joycie (12-17-2012)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Alternatively you can set that in the 4th parameter of the mail() function call. If that doesn't work, the 5th parameter can force it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Joycie (12-17-2012)

  • #5
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question

    Quote Originally Posted by Fumigator View Post
    The error is in how you have SMTP configured to work with your PHP install. Fix that and your mail() function will work.
    hi Fumigator, I had a look for the php.ini file - are we talking about the c/xampp/php/php.ini file? sorry, I'm rather new to this...

  • #6
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question

    Quote Originally Posted by AndrewGSW
    Have you configured the From header in php.ini?
    Hi AndrewGSW, had a look at the php.ini but not sure what to change...frankly, a little scared to change anything without being sure what to change! Feeling slightly retarded here, but hey ho, gotto start somewhere as a beginner! Could you give me a hint of what to change within the php.ini and in what format to save the file? I'm with GoDaddy if that is of any help ;-) x
    Last edited by Joycie; 12-16-2012 at 09:57 PM.

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    hi Fumigator, I had a look for the php.ini file - are we talking about the c/xampp/php/php.ini file? sorry, I'm rather new to this...
    This is your local .ini file so is only relevant for testing. Your host may have their own version of this file although it is not always accessible to you directly.

    If you are not sending emails from a number of pages then you could just add 'From: ' to the mail() call in your current page. The docs. (Setting From in the php.ini file sets it as a default when sending emails.) Make sure that the additional header(s) you add end with '\r\n'. Example:
    PHP Code:
    <?php
    $to      
    'nobody@example.com';
    $subject 'the subject';
    $message 'hello';
    $headers 'From: webmaster@example.com' "\r\n" .
        
    'Reply-To: webmaster@example.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

    mail($to$subject$message$headers);
    ?>
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Joycie (12-17-2012)

  • #8
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question

    Quote Originally Posted by AndrewGSW View Post
    If you are not sending emails from a number of pages then you could just add 'From: ' to the mail() call in your current page.
    Hi Andrew, thank you so much for giving me some directions - however, the issue is still not solved. I have tried different changes in the script but none of them seem to work...I'm close to just redoing the whole page, how frustrating is this!!!

    GoDaddy support advices me: "If you use the mail() function in your PHP, you do not need to specify an outgoing mail server. If you are using some other method besides mail() in your PHP code, use relay-hosting.secureserver.net for your relay server."

    Although I am using mail() is there still a way of adding the relay server to the headers section, and maybe give that a go...or is there no point trying

  • #9
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    I think you can specify the smtp server like:
    ini_set ( "SMTP", "relay-hosting.secureserver.net" ); but that doesn't see like the problem. 451 is internal SMTP server error. Something similar is discussed here.

    http://support.jodohost.com/threads/...l-in-e-a.8774/

    Replace all \n with \r\n in body and you should be okay.
    Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon

  • Users who have thanked alemcherry for this post:

    Joycie (12-17-2012)

  • #10
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Thumbs up Big YEAH!!!

    Quote Originally Posted by alemcherry View Post
    I think you can specify the smtp server like:
    ini_set ( "SMTP", "relay-hosting.secureserver.net" ); but that doesn't see like the problem. 451 is internal SMTP server error. Something similar is discussed here.

    http://support.jodohost.com/threads/...l-in-e-a.8774/

    Replace all \n with \r\n in body and you should be okay.
    Wooohoooo you superstar!!! It is doing the job Big YEAH for those who have helped me with this!!!! If I can place a link to any of your sites on my link page, let me know

    One more lil issue...my 'copy to yourself' is not working yet...any suggestions?

    // Set email variables
    $email_to = 'info@mail.net';
    $email_subject = 'Feedback';
    ini_set("SMTP","relay-hosting.secureserver.net");
    ini_set("sendmail_from","info@mail.net");
    $ccto = 'email';

    // simple email content
    foreach($_POST as $key => $value) {
    if($key != 'submit') $email_content .= $key . ': ' . $value . "\r\n";
    }

    $ccto .= $_POST['Copy to yourself'] == "tick" ? "Copy to yourself: Yes \n" : "Copy to yourself: No \n";

    // if validation passed ok then send the email
    mail($email_to, $email_subject, $email_content, $sendmail_from, $ccto);

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This isn't right: mail($email_to, $email_subject, $email_content, $sendmail_from, $ccto); . Parameters here are to, subject, content, headers, and finally parameters. $sendmail_from may be a parameter, but if you have it working as is that indicates that its simply a header.
    If you want to send a copy to yourself, $ccto is abandoned and $sendmail_from can add an additional header for 'cc:' ie: $sendmail_from .= "Cc: <an address>\r\n".

  • Users who have thanked Fou-Lu for this post:

    Joycie (12-17-2012)

  • #12
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question

    Quote Originally Posted by Fou-Lu View Post
    If you want to send a copy to yourself, $ccto is abandoned and $sendmail_from can add an additional header for 'cc:' ie: $sendmail_from .= "Cc: <an address>\r\n".
    Thank you Fou-Lu, I have now changed the header code!
    Though regarding the CC, it won't be a CC to me but to the actual sender of the message.

    I have been searching of how to CC the message as an attachment to prevent mail spamming...any suggestions?

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can use whatever address you want in the cc. You can also specify multiple addresses in the to header by separating them with a comma. Presumably you have a method of gathering the email address from the user (which may or may not be a real email address / belong to the original author).

    I don't understand what you mean by sending the message as an attachment. Do you mean by creating a text file that they can download as an attachment from the email? Seems a little over the top to me (and would solve nothing of course); you'll need to come up with a more vigorous spam identification approach to completely discard what is identified as spam or queue it for approval.

  • Users who have thanked Fou-Lu for this post:

    Joycie (12-17-2012)

  • #14
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post
    Hi Fou-Lu!

    I've just been reading a lot but lacking the experience, therefore I'm asking around - your opinion is well appreciated!!!

    As the email will be a Cc to the actual sender of the message, I don't know the Cc email direction in advance...Any suggestions of how to set the // Set email variables & // simple email content for a checkbox to attach a copy of the message to the actual sender without knowing their email?

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No, that's impossible. The email address must be provided to you in order to determine where to send it. You can use checkboxes to determine if it should send a copy, but the email address has to come from somewhere.
    If you have a system where the user logs into, chances are they provided an email during registration. You can always retrieve that and use it.

    Client side you can do this though (sorta). Using the mailto: link in HTML will open the client's standard email client. You can provide it with information within the link (limited to about 65K characters including the encoded entities) as a part of the querystring (see this wiki article for some examples: http://en.wikipedia.org/wiki/Mailto), but you won't be able to preprocess the data sent by the form. Best you can do is process the form to generate the link, and let them click on the link.
    This way they send it using their mail and not yours.

  • Users who have thanked Fou-Lu for this post:

    Joycie (12-17-2012)


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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