Suite à mes petits soucis de CGI (cf Post précédent) j'ai changé mon fusil d'épaule en téléchargeant puis en modifiant à ma convenance un script php récupérant les infos de mon formulaire, les mettant en forme puis les envoyant par mail.
Tout marche (pour une fois
), la page de validation d'envoi s'affiche avec les bonnes infos (voir le script) mais j'attends toujours mes mails moi
!!
Voici le script :
<?
////////////////////////////////////////////////////////////
//
// spidermail.php - a complex form mailer
//
////////////////////////////////////////////////////////////
//
// This script e-mails all the name and value pairs from
// a submitted form to the specified "to" address using HTML
// and e-mail templates.
//
// See readme.txt for more information.
//
// Author: Jon Thomas <http://jp.thomas.name>
// Last Modified: 4/23/03
//
// You may freely use, modify, and distribute this script.
//
////////////////////////////////////////////////////////////
// define the variables
$defaultTo = "[email protected]";
$defaultFrom = "[email protected]";
$defaultSubj = "Demande de validation de bon de commande Eurorepar";
$htmlTemplate = "tem_html.txt";
$emailTemplate = "tem_email.txt";
// optional URL of the submission form to prevent off-site use
$formURL = "";
// DO NOT EDIT BELOW THIS POINT UNLESS YOU KNOW PHP! //
// if a form URL is specified
if ($formURL != "") {
// check whether referrer matches form URL
if ($HTTP_REFERER != $formURL) {
// quit script if no match
die("Illegal use.");
}
}
// include function files
include("is_email.inc");
include("replaceArrStrs.inc");
include("selectText.inc");
$to = $defaultTo;
$from = $defaultFrom;
$subject = $defaultSubj;
// get the date and time
$datetime = date('l, F j \a\t g:i A T');
// get the complete templates
$html = file($htmlTemplate);
$email = file($emailTemplate);
// add header data to the templates
if (isset($toAlias)) {
$html = preg_replace("/<!--TO-->/", $toAlias, $html);
$email = preg_replace("/<!--TO-->/", $toAlias, $email);
}
else {
$html = preg_replace("/<!--TO-->/", $to, $html);
$email = preg_replace("/<!--TO-->/", $to, $email);
}
$html = preg_replace("/<!--FROM-->/", $from, $html);
$html = preg_replace("/<!--SUBJECT-->/", $subject, $html);
$html = preg_replace("/<!--FORM URL-->/", $HTTP_REFERER, $html);
$html = preg_replace("/<!--DATETIME-->/", $datetime, $html);
$email = preg_replace("/<!--FROM-->/", $from, $email);
$email = preg_replace("/<!--SUBJECT-->/", $subject, $email);
$email = preg_replace("/<!--FORM URL-->/", $HTTP_REFERER, $email);
$email = preg_replace("/<!--DATETIME-->/", $datetime, $email);
// add each name/value pair to the body
while(list($name, $value) = each($HTTP_POST_VARS)) {
// do not include the script's internal data with the submission
if ($name == "to" || $name == "from" || $name == "subject" || $name == "url") {
continue;
}
// get the body pair templates
$html_pair = selectText("tem_html.txt", "<!--BEGIN BODY-->", "<!--END BODY-->", 0);
$email_pair = selectText("tem_email.txt", "<!--BEGIN BODY-->", "<!--END BODY-->", 0);
// add the name to this body pair
$html_pair = preg_replace("/<!--NAME-->/", $name, $html_pair);
$email_pair = preg_replace("/<!--NAME-->/", $name, $email_pair);
// if the value is an array, print the values separated by commas
if (is_array($value)) {
// build a list of values
for ($i = 0; $i < count($value); $i++)
{
// if this value is the last, don't print another comma
if (count($value) == ($i + 1)) {
$values .= "$value[$i]";
}
// otherwise, print a comma and space after this value
else {
$values .= "$value[$i], ";
}
}
// add the values to this body pair
$html_pair = preg_replace("/<!--VALUE-->/", $values, $html_pair);
$email_pair = preg_replace("/<!--VALUE-->/", $values, $email_pair);
}
// otherwise, add the single value to this body pair
else {
$html_pair = preg_replace("/<!--VALUE-->/", $value, $html_pair);
$email_pair = preg_replace("/<!--VALUE-->/", $value, $email_pair);
}
// add this pair to the bodies
$html_body .= $html_pair;
$email_body .= $email_pair;
}
// add the bodies to the templates
$html = replaceArrStrs($html, "<!--BEGIN BODY-->", "<!--END BODY-->", 1, $html_body);
$email = replaceArrStrs($email, "<!--BEGIN BODY-->", "<!--END BODY-->", 1, $email_body);
// create strings from the template arrays
$html = join("", $html);
$email = join("", $email);
// if the submission fails, print an error msg
if(!mail($to, $subject, $email, "From: $from")) {
echo "<b>Error:</b> Your mail was not sent. Contact the webmaster for help.";
// and terminate the script
exit();
}
// if a url is set, take the user there
if (isset($url)) {
header("Location: $url");
}
// otherwise, print the submission to the screen
else {
echo $html;
}
?>
Sachant que mon serveur est en intranet (mon poste en fait
) sous apache (10.2.6) il y a-t-il qqch à configurer du coté de sendmail ? ou du coté de la fonction mail de php ?
A votre avis ?
Merci
Tout marche (pour une fois
Voici le script :
<?
////////////////////////////////////////////////////////////
//
// spidermail.php - a complex form mailer
//
////////////////////////////////////////////////////////////
//
// This script e-mails all the name and value pairs from
// a submitted form to the specified "to" address using HTML
// and e-mail templates.
//
// See readme.txt for more information.
//
// Author: Jon Thomas <http://jp.thomas.name>
// Last Modified: 4/23/03
//
// You may freely use, modify, and distribute this script.
//
////////////////////////////////////////////////////////////
// define the variables
$defaultTo = "[email protected]";
$defaultFrom = "[email protected]";
$defaultSubj = "Demande de validation de bon de commande Eurorepar";
$htmlTemplate = "tem_html.txt";
$emailTemplate = "tem_email.txt";
// optional URL of the submission form to prevent off-site use
$formURL = "";
// DO NOT EDIT BELOW THIS POINT UNLESS YOU KNOW PHP! //
// if a form URL is specified
if ($formURL != "") {
// check whether referrer matches form URL
if ($HTTP_REFERER != $formURL) {
// quit script if no match
die("Illegal use.");
}
}
// include function files
include("is_email.inc");
include("replaceArrStrs.inc");
include("selectText.inc");
$to = $defaultTo;
$from = $defaultFrom;
$subject = $defaultSubj;
// get the date and time
$datetime = date('l, F j \a\t g:i A T');
// get the complete templates
$html = file($htmlTemplate);
$email = file($emailTemplate);
// add header data to the templates
if (isset($toAlias)) {
$html = preg_replace("/<!--TO-->/", $toAlias, $html);
$email = preg_replace("/<!--TO-->/", $toAlias, $email);
}
else {
$html = preg_replace("/<!--TO-->/", $to, $html);
$email = preg_replace("/<!--TO-->/", $to, $email);
}
$html = preg_replace("/<!--FROM-->/", $from, $html);
$html = preg_replace("/<!--SUBJECT-->/", $subject, $html);
$html = preg_replace("/<!--FORM URL-->/", $HTTP_REFERER, $html);
$html = preg_replace("/<!--DATETIME-->/", $datetime, $html);
$email = preg_replace("/<!--FROM-->/", $from, $email);
$email = preg_replace("/<!--SUBJECT-->/", $subject, $email);
$email = preg_replace("/<!--FORM URL-->/", $HTTP_REFERER, $email);
$email = preg_replace("/<!--DATETIME-->/", $datetime, $email);
// add each name/value pair to the body
while(list($name, $value) = each($HTTP_POST_VARS)) {
// do not include the script's internal data with the submission
if ($name == "to" || $name == "from" || $name == "subject" || $name == "url") {
continue;
}
// get the body pair templates
$html_pair = selectText("tem_html.txt", "<!--BEGIN BODY-->", "<!--END BODY-->", 0);
$email_pair = selectText("tem_email.txt", "<!--BEGIN BODY-->", "<!--END BODY-->", 0);
// add the name to this body pair
$html_pair = preg_replace("/<!--NAME-->/", $name, $html_pair);
$email_pair = preg_replace("/<!--NAME-->/", $name, $email_pair);
// if the value is an array, print the values separated by commas
if (is_array($value)) {
// build a list of values
for ($i = 0; $i < count($value); $i++)
{
// if this value is the last, don't print another comma
if (count($value) == ($i + 1)) {
$values .= "$value[$i]";
}
// otherwise, print a comma and space after this value
else {
$values .= "$value[$i], ";
}
}
// add the values to this body pair
$html_pair = preg_replace("/<!--VALUE-->/", $values, $html_pair);
$email_pair = preg_replace("/<!--VALUE-->/", $values, $email_pair);
}
// otherwise, add the single value to this body pair
else {
$html_pair = preg_replace("/<!--VALUE-->/", $value, $html_pair);
$email_pair = preg_replace("/<!--VALUE-->/", $value, $email_pair);
}
// add this pair to the bodies
$html_body .= $html_pair;
$email_body .= $email_pair;
}
// add the bodies to the templates
$html = replaceArrStrs($html, "<!--BEGIN BODY-->", "<!--END BODY-->", 1, $html_body);
$email = replaceArrStrs($email, "<!--BEGIN BODY-->", "<!--END BODY-->", 1, $email_body);
// create strings from the template arrays
$html = join("", $html);
$email = join("", $email);
// if the submission fails, print an error msg
if(!mail($to, $subject, $email, "From: $from")) {
echo "<b>Error:</b> Your mail was not sent. Contact the webmaster for help.";
// and terminate the script
exit();
}
// if a url is set, take the user there
if (isset($url)) {
header("Location: $url");
}
// otherwise, print the submission to the screen
else {
echo $html;
}
?>
Sachant que mon serveur est en intranet (mon poste en fait
A votre avis ?
Merci