Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-08-2007, 01:08 PM Form error
Skilled Talker

Posts: 89
Trades: 0
I made some forms. The mainly work, but they don't actually send the email. When I try and send it it gives me this error.

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\New Goldfish\contact.php on line 98

I am testing it on Wamp, but I don't know if that matters. Hear is my code... I would appreciate it if someone could help me fix this.


Code:
<?php
include('Includes/corefuncs.php');
if (function_exists('nukeMagicQuotes')) {
  nukeMagicQuotes();
  }
  
/////////////////////////////////////////////////

//go ahead only if not suspect and all required fields OK
if (!$suspect && empty($missing)) {
    //set defaul values for variables that might not exist
    $quote = isset($quote) ? $subscribe : 'Nothing Selected';
}
///////////////////////////////////////////////////////////

$subject = 'Project Idea';

//list expected feilds
  $expected = array('name', 'email', 'budget', 'comments');
//set required fields
  $required = array('name', 'comments', 'email');
//creat an empty array for any missing fields
$missing = array();

///////////////////////////////////////////////////////////

//process email
if (array_key_exists('send', $_POST)) {
  $to = "goldfishgraphics@gmail.com"; //my email
  $subject = "Project Idea";

 

  
//create empty array for any missing fields
$missing = array();
//assume that there is nothing suspect
$suspect = false;
//create a pattern to locate suspect phrases
$pattern = '/Content-Type:|Bcc:|Cc:/i';

//function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
    // if the variable is an array, loop through each element
    // and pass it recursively back to the same function
    if (is_array($val)) {
        foreach ($val as $item) {
            isSuspect($item, $pattern, $suspect);
        }
    }
    else {
        // if one of the suspect phrases is found, set Boolean to tur
        if (preg_match($pattern, $val)) {
            $suspect = true;
        }
    }
}

// check the $_POST array and any subarrays for suspect content
isSuspect($_POST, $pattern, $suspect);

if ($suspect) {
    $mailSent = false;
    unset($missing);
}
else {

//process the $_POST variables
foreach ($_POST as $key => $value) {
    //asign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
    //if empty and required, add to $missing array
    if (empty($temp) && in_array($key, $required)) {
        array_push($missing, $key);
    }
    //otherwise, assign to a variable of the same name as $key
    elseif (in_array($key, $expected)) {
        ${$key} = $temp;
    }
}
}
//build the message

//go ahead if required feilds are in
if (!$suspect && empty($missing)) {

//build message
  $message = "Name: $name\n\n";
  $message .= "Email: $email\n\n";
  $message = "Budget: $budget\n\n";
  $message .= "Comments: $comments";
  
//limit line length to 65 characters
  $message = wordwrap($message, 65);

// send it
$mailSent = mail($to, $subject, $message);
if ($mailsent) {
  //missing is no longer needed if the meail is sent, so unset it
  unset($missing);
    }
     }
    }

?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<!-- Form CSS -->
<style type=”text/css”>

label {display: block;} /* make sure that the input will be displayed below the label */
.text_input {width: 450px;margin-bottom: 5px;} /* each input field with a class value of text_input will be 450px wide and will have a margin of 5px on the bottom */
textarea {width: 450px ! important;height: 150px;} /* each <textarea> tag will be 450px wide and have a height of 150px*/
</style>
<!-- (((((()))))) -->

<title>Goldfish Graphics</title>

<link rel="stylesheet" type="text/css" href="main.css">

</head>

<body>

<div id="container">

  <div id="header">
    <!-- PUT HEADER CODE HERE -->
  </div>
  
  <div id="contentt">
    <!-- PUT CONTENTT CODE HERE -->
  </div>

  <div id="content">
    <!-- CONTENT CODE -->
    <?php
    @include('Includes/menue.html');
    ?>
    
    <h3 class="heading">Contact</h3>
<!-- FORM CODE ***************************************** -->

<form name="feedback" action="" method="post" class="bcontent">

<label for="name">Name</label>
    <input name="name" id="name" type="text" class="formbox"
    <?php if (isset($missing)) {
      echo 'value="'.htmlentities($_POST['name']).'"';
    } ?>/>
    
<br /><br />

<label for="email">Email</label>
    <input name="email" id="email" type="text" class="formbox"
    <?php if (isset($missing)) {
      echo 'value="'.htmlentities($_POST['email']).'"';
    } ?>/>
    
<br /><br />

    <label for="budget">Budget</label>
    <input name="budget" id="budget" type="text" class="formbox"
    <?php if (isset($missing)) {
      echo 'value="'.htmlentities($_POST['budget']).'"';
    } ?>/>
    
<br /><br />

<label for="comments">Prodject Description</label>
<br /><br />
    <textarea name="comments" id="comments" cols="50" rows="10"><?php 
    if (isset($missing)) {
        echo htmlentities($_POST['comments']);
    } ?></textarea> 

<br /><br />
<input name="send" id="send" type="submit" value="Submit" />

</form>

<?php
if ($_POST && isset($missing)) {
?>
  <p class="bcontent">Please complete all required missing item(s).</p>
<?php
 }
elseif ($_POST && !$mailSent) {
?>
  <p class="bcontent">Sorry, there was a problem sending your message. Please try later.</p>
<?php
 }
elseif ($_POST && $mailSent) {
?>
  <p class="bcontent"><strong>Your message has been sent. Thank you.
</strong></p>
<?php }?>

<!-- FORM CODE ********************************************* -->
    <p class="bcontent">
    If you have questions, comments, or troubles with the form above, you can also contact me at <b>goldfishgraphics@gmail.com.</b>
    </p>
    
  </div>

  <div id="contentb">
    <!-- CONTENTB CODE -->
  </div>

  <div id="footer">
    <!-- PUT FOOTER CODE HERE -->
    
    <p class="copyright" align="center">&copy; 
         <?php ini_set('date.timezone', 'American/Eastcoast');
         $startYear = 2007;
         $thisYear = date('Y');
         if ($startYear == $thisYear) {
         echo $startYear;
         }
         else {
         echo "{$startYear}-{$thisYear}";
         }
         ?>
    Goldfish Graphics</p>
  
  </div>

</div>

</body>
</html>
Bouzy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-08-2007, 02:15 PM Re: Form error
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I dont think i have to even look at the code to know, When i try to test a mail script on my localhost testing server it also shows this error.

I think its to do with the server PHP configurations. not sure how to fix it but if you test it on a live server it should all work

Talkupation Apprieciated
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-08-2007, 02:39 PM Re: Form error
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP cannot send email directly on windows.
On that platform, you need to edit php.ini, and setup the smtp (simpl mail transfer protocol) server and user/pass to speak either with a server of yours, or your isp server.

When I'm forced to be on windows, I use apacheFriends xampp, their wamp distro include an smtp server, which can be used to send/receive mails locally on the computer you develop.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-08-2007, 04:00 PM Re: Form error
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I thought so, im using XAMPP too, but i havent both to set up or even have my mail server running.

i would love to one day get a home server going... running as a mail server, buy a domain for the server IP dansmail.co.uk hehe

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-08-2007, 05:48 PM Re: Form error
Skilled Talker

Posts: 89
Trades: 0
I don't know how to do that so I will just wait till I get a real server.
Bouzy is offline
Reply With Quote
View Public Profile
 
Old 09-08-2007, 05:53 PM Re: Form error
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
If you dont currently have webhosting i might be able to help :-)

if your interested, i can ooffer you some hosting, and not expensive either!

Pm me or email me or add me
either way ill get it

email: admin@dansgalaxy.co.uk
msn: dansgalaxy@hotmail.co.uk

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-09-2007, 09:26 AM Re: Form error
Ultra Talker

Posts: 483
Trades: 0
You can definitely get a mail server to work on your computer. If you're getting that error then I would check that:
a) the mail server is actually set up and running; and
b) your firewall is not blocking access to the port.

Not that it helps anything past testing... most ISPs will block the connection from your local mail server to wherever it's trying to send the mail.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 09-09-2007, 10:46 AM Re: Form error
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I know my ISP NTL VirginMedia has been quite a pain! i havent botherd to set up a local mail server, but i use my own hosting for all my emails (not good when your host decided he dont wanna pay his bill... i had no email for a week!! - hell) anyway, i could recieve my mail perfectly find, but the request got refused when i try to send. via Port 25 i wrote the a few rather peeved (and yet Very polite) emails got a auto response for each and everyone explaining how "we?ll" (yes... a big huge company like Virgin STILL dont know what charset to send emails as!) that they busy and i should expect a tech to contact me within a week etc ...

Nothing...

anyway musteriously after my first 2 emails suddenly hey presto i could send emails! and then a week later it started to block again...

anyway now it seems that they have unblocked it and its working

i uno ISPs are weird as hell!
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Form error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26998 seconds with 12 queries