the action is generated using
so i don't think that's the problem
I'm aware of SPForm, i used it until recently but wanted to add the functionality to double-check one's email after sending the msg cause i get lots of wrong emails and i can't get back to them :-(
I'll take a look at FormIt
here's my code (php newbie, so some things might look odd)
<?php
//OPTIONS
// email = which mail to send to (default: [email protected])
// subject = prepend this text to the subject (optional)
// successMsg = message to print when successfully sent email (Defaul as set below))
//SET VARS
// $sender = the user must insert that in contact form and i will get this with _Post
$email = $modx->getOption('email',$scriptProperties,'[email protected]');
$successMsg = $modx->getOption('successMsg',$scriptProperties,'<i>Check that the above address is correct, or else we will not be able to contact you back.(If it isn\'t, send us your message again)</i><br><strong>We will get back to you as soon as possible!</strong>');
//Print the contact form
echo '<form method="post" action="'.$modx->makeUrl($modx->resource->get('id'),'','','http').'">';
echo '<p>Your name:<br /><input name="name" /></p>';
echo '<p>Your email:<br /><input name="email" /></p>';
echo '<p class="antispam">Leave this empty:<br /><input name="url" /></p>';
echo '<p>Subject:<br /><input name="subject" /></p>';
echo 'Message:<br><textarea rows="10" cols="25" name="message"></textarea>';
echo '<br><input type="submit" value="Send" />';
echo '</form>';
//insert the antispam css
$modx->regClientStartupHTMLBlock('<!--Next lines are inserted by contactForm snippet for antispam reasons -->
<style type="text/css">
.antispam { display:none;}
</style>');
//Check if the form has been posted or if it's the first time the page has been loaded
if (!isset($_POST['name'])) {return ;}
//Test for validations
$ok = true;
$errorMsg = 'Mail was not sent. Please fix the following error(s):<ul>';
if (empty($_POST['name'])) {$ok = false; $errorMsg .= '<li>Name is empty. Please enter your name.</li>';}
if (!validEmail($_POST["email"])) {$ok = false; $errorMsg .= '<li>The email you entered is not valid. Please make sure it\'s correct so we can answer to you.</li>'; }
if (empty($_POST['message'])) {$ok = false; $errorMsg .= '<li>Message is empty. Did you forget what you wanted to tell us?</li>';}
$errorMsg .= '</ul>';
if (!$ok){return $errorMsg;}
//Send the actual messages
if(isset($_POST['url']) && $_POST['url'] == ''){
//Send mail to us
// Build the text to be sent
$msg = $_POST["name"].' <'.$_POST["email"].'> wrote:'."\n\n";
$msg .= $_POST["message"];
//Build headers
$headers = 'From:'.$_POST["email"] . "\r\n" .
'Reply-To:'.$_POST["email"] . "\r\n" ;
// email
mail( $email, $subject." ".$_POST["subject"], $msg, $headers);
//Send a copy to the visitor
// Build the text to be sent
$msg = "You successfully sent the following message to Athens Lindy Hop.\nThank you for contacting us, we will get back to you as soon as possible.\n\nΣτείλατε επιτυχώς το παρακάτω μήνυμα στους Athens Lindy Hop.\nΕυχαριστούμε για την επικοινωνία και θα απαντήσουμε το συντομότερο.\n\n---------\nOriginal message: \n\n";
$msg .= $_POST["name"].' <'.$_POST["email"].'> wrote:'."\n\n";
$msg .= '> '.str_replace("\n", "\n> ", $_POST["message"]);
//Build headers
$headers = 'From:[email protected]' . "\r\n" .
'Reply-To:[email protected]' . "\r\n" ;
// email
mail( $_POST['email'], "Message sent to Athens Lindy Hop", $msg, $headers);
//Display a confirmation message on screen
return '<p style="font-size:larger"> <span style="color: green"> Message successfully sent from:</span> <b>'.$_POST['email'].'</b></p>'.$successMsg;
}
/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
*/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
↪checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}