Jump to content

Webbased Email Forum


stanmancan

Recommended Posts

Hey all...

 

First off, I'm no PHP programmer here. Our companies website was written in PHP and the employee was fired shortly after. Now, our website is in PHP and it's time to make some changes!

 

I've beaten my way through it and managed to give the site a completely new facelift, which is the first step. But, we would like to add a new function. Customers can come to our site and fill out something like.

 

Name

Address

Product

Question

 

Hit submit, and have it e-mail us.

 

I downloaded some code off the net, as I can't write it myself. I went in and changed the php.ini to say

 

[mail function]

; For Win32 only.

SMTP = shawmail

smtp_port = 25

 

I reboot the server, but when I try to use the code snippet it says:

 

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 C:\Websites\**company**\FormToEmail.php on line 177

 

Why would it say "localhost" when I changed it to shawmail?

 

Any idea's? I'd just like to get this working :)

 

 

Now, one thing is, I'm not sure if the employee actually setup PHP correctly or if he just ran the exe (which I've read your _NOT_ supposed to do). I only say this becuase I thought normally the php.ini was suppiosed to be located in C:\Windows. Here, it's located in C:\PHP. There's also a php.zip file that he looks like he just extracted.

 

Any help would be _GREATLY_ appreciated.

 

Likewise, if you have a code snippet or something of the sort for this function, nothing's set in stone I'd be happy to change what I'm doing now if it's easier.

 

(For the record, we're looking to do something liek this: http://en-ca.maitredpos.ca/products/inquiry/default.aspx

Link to comment
https://forums.phpfreaks.com/topic/111527-webbased-email-forum/
Share on other sites

You need to make sure that the php.ini that you are changing is the one that php is using. Create a .php file with the following and browse to it -

 

<?php
phpinfo();
?>

 

In the first section of the output, there will be a line like the following that shows if and what php.ini is being loaded -

 

Loaded Configuration File
Link to comment
https://forums.phpfreaks.com/topic/111527-webbased-email-forum/#findComment-572408
Share on other sites

If you are using an Apache web server, the easiest way is to put a PHPIniDir statement in your httpd.conf file that points to the php.ini that you are using. Stop and start your web server to get any changes made to httpd.conf to take effect. Something like -

 

PHPIniDir "C:\PHP"

Link to comment
https://forums.phpfreaks.com/topic/111527-webbased-email-forum/#findComment-572472
Share on other sites

Here is the code I got off the net.

I don't get the error that it can't send anymore, it says it's been sent successfully. But I also never get the e-mail. Any ideas? I'm using IIS on Windows 2003 Server.

 

Also, I got the PHP.ini file loading, I had to add something to the windows enviroment variables..

 

<?php


$my_email = "[email protected]";


$continue = "http://www.test.com";


$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Validate email field.

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

// Check referrer is from same site.



// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";

$message = stripslashes($message);

$subject = "FormToEmail Comments";

$headers = "From: " . $_REQUEST['email'];
$headers .= PHP_EOL;
$headers .= "Return-Path: " . $_REQUEST['email'];
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];
mail($my_email,$subject,$message,$headers);

?>

Link to comment
https://forums.phpfreaks.com/topic/111527-webbased-email-forum/#findComment-572518
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.