Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2011, 06:05 PM   PM User | #1
michaelli321
New Coder

 
Join Date: Aug 2011
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
michaelli321 is an unknown quantity at this point
Problem With Sending Email Through PHP

I downloaded and installed XAMPP on my computer, which includes mysql, php, apache, and mercury. I am currently running everything on localhost. I created a form that was supposed to send an email to me, but I get this error:


Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in

Here is my code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Contact Me</title>
</head>
<body>
    <h1>Contact Me</h1>
    <?php # Script 10.1 - email.php
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
        
        // Minimal for validation:
        if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) {
            
            // Create the body:
            $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}";
            
            // Make it no longer than 70 characters long:
            $body = wordwrap($body, 70);
            
            // Send the email:
            mail('li.michael1998@gmail.com', 'Contact Form Submission', $body, "From: {$_POST['email']}");
            
            // Print a message:
            echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>';
            
            // Clear $_POST (so that the form's not sticky):
            $_POST = array();
            
        } else {
            echo '<p style="font-weight: bold; color: #C00">Please fill out the form completely.</p>';
        }
        
    } // End of main isset() IF.
    
    // Create the HTML form:
    ?>
    <p>Please fill out this form to contact me.</p>
    <form action="email.php" method="post">
        <p>Name: <input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
        <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
        <p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p>
        <p><input type="submit" name="submit" value="Send!" /></p>
        <p><input type="hidden" name="submitted" value="TRUE" />
    </form>
</body>
</html>
I'm not sure if I need to download something else, or configure php.ini or what. Any help?
michaelli321 is offline   Reply With Quote
Old 08-23-2011, 06:12 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
I think you'll find with xampp that you need to configure fakesendmail (or similar) to use an SMTP server. By that I mean you need to set your username and password.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-23-2011, 06:28 PM   PM User | #3
michaelli321
New Coder

 
Join Date: Aug 2011
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
michaelli321 is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
I think you'll find with xampp that you need to configure fakesendmail (or similar) to use an SMTP server. By that I mean you need to set your username and password.
Sorry I'm new to computer programming and stuff, how would I do that?
michaelli321 is offline   Reply With Quote
Old 08-23-2011, 06:35 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Look in the xampp directory for a directory called fakesendmail (or similar). Go into it and set up the configuration file with your connection settings.

Shouldn't you be asking this on the xampp website? - The error you received is not POHP related. It's a reply from your ISPs SMTP server. Therefor this is not a PHP issue and really the most obvious (and best) place to ask is in the xampp support section of their website.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Tags
email, error, mail server, php, smtp

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.