ram
asked on
How to set php.ini variables in web.config file to make contact form work?
I have a contact form that I copied and altered a bit, and it uses php coding to verify and send user input using the mail function in php. I have tested the form both locally and on the web server but it doesn't seem to work since I am not receiving any emails.
After some reading, I found out that in order for the form to work, I have to configure some things in the php.ini file. I called my web server host and they told me that I don't have access to the php.ini file. But they did tell me that I can make changes in the web.config file, which I do have access to. Can anyone please help me set this up? I am a beginner in web development and I am not familiar with the server-side of things.
After some reading, I found out that in order for the form to work, I have to configure some things in the php.ini file. I called my web server host and they told me that I don't have access to the php.ini file. But they did tell me that I can make changes in the web.config file, which I do have access to. Can anyone please help me set this up? I am a beginner in web development and I am not familiar with the server-side of things.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all for your help! I will definitely consider all of your suggestions.
Here's my teaching example of a form-to-email script. It contains the "action" script that processes the request from the form in lines 18-50. It contains the "form" script (generated by a HEREDOC block) in lines 53-65. There is a function that we use to clean up external input, too. You might try installing it and running it "as-is" with only the changes noted in the comments at the top. In my experience, this almost always works correctly in the standard PHP installation.
<?php // demo/form_to_email.php
/**
* Use PHP to Send Email from an HTML Form
*/
error_reporting(E_ALL);
// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from = 'NoReply@Your.org';
$subj = 'Contact Form';
// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[] = 'You@Your.org';
$to[] = 'Her@Your.org';
$to[] = 'Him@Your.org';
// IF THE DATA HAS BEEN POSTED (AT LEAST SOMETHING IN THE EMAIL INPUT CONTROL)
if (!empty($_POST['e']))
{
// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
$safe_mail = clean_string($_POST['e']);
$safe_name = clean_string($_POST['n']);
$safe_fone = clean_string($_POST['t']);
$safe_idea = clean_string($_POST['i']);
// CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
$content = NULL;
$content .= "You have a New Query From $safe_name" . PHP_EOL . PHP_EOL;
$content .= "Tel No: $safe_fone" . PHP_EOL;
$content .= "Email: $safe_mail" . PHP_EOL;
$content .= "Idea: $safe_idea" . PHP_EOL;
// SEND MAIL TO EACH RECIPIENT
foreach ($to as $recipient)
{
if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
{
echo PHP_EOL . "<br/>MAIL FAILED FOR $recipient";
}
else
{
echo PHP_EOL . "<br/>MAIL WORKED FOR $recipient";
}
}
// PRODUCE THE THANK-YOU PAGE
echo '<p>THANK YOU</p>' . PHP_EOL;
die('TASK COMPLETE');
}
// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="e" />
<br/>Phone: <input name="t" />
<br/>Name: <input name="n" />
<br/>Ideas? <textarea name="i"></textarea>
<br/><input type="submit" />
</form>
ENDFORM;
echo $form;
// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
// IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
$str = stripslashes($str);
// REMOVE EXCESS WHITESPACE
$rgx
= '#' // REGEX DELIMITER
. '\s' // MATCH THE WHITESPACE CHARACTER(S)
. '\s+' // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
. '#' // REGEX DELIMITER
;
$str = preg_replace($rgx, ' ', $str);
// REMOVE UNWANTED CHARACTERS
$rgx
= '#' // REGEX DELIMITER
. '[' // START OF A CHARACTER CLASS
. '^' // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
. 'A-Z0-9' // KEEP LETTERS AND NUMBERS
. '"' // KEEP DOUBLE QUOTES
. "'" // KEEP SINGLE QUOTES
. '@&+:?_.,/\-' // KEEP SOME SPECIAL CHARACTERS (NOTE ESCAPED HYPHEN)
. ' ' // KEEP BLANKS
. ']' // END OF THE CHARACTER CLASS
. '#' // REGEX DELIMITER
. 'i' // CASE-INSENSITIVE
;
$str = preg_replace($rgx, NULL, $str);
// REMOVE EXCESSIVE INPUT
$str = substr($str, 0, 255);
return trim($str);
}
ASKER
Open in new window
And here is the the HTML Code:
Open in new window