diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 4fe46859dc7..b06f360653e 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -462,9 +462,9 @@ if (empty($reshook)) { $mesgs = array(); - $object->email_from = GETPOST("from"); - $object->email_replyto = GETPOST("replyto"); - $object->email_errorsto = GETPOST("errorsto"); + $object->email_from = GETPOST("from", "none"); // Must allow 'name ' + $object->email_replyto = GETPOST("replyto", "none"); // Must allow 'name ' + $object->email_errorsto = GETPOST("errorsto", "none"); // Must allow 'name ' $object->title = GETPOST("title"); $object->sujet = GETPOST("sujet"); $object->body = GETPOST("bodyemail", 'restricthtml'); @@ -491,7 +491,7 @@ if (empty($reshook)) $mesgs[] = $object->error; } - setEventMessages($mesg, $mesgs, 'errors'); + setEventMessages(null, $mesgs, 'errors'); $action = "create"; } @@ -501,11 +501,10 @@ if (empty($reshook)) $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing'); if ($action == 'settitle') $object->title = trim(GETPOST('title', 'alpha')); - elseif ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from', 'alpha')); - elseif ($action == 'setemail_replyto') $object->email_replyto = trim(GETPOST('email_replyto', 'alpha')); - elseif ($action == 'setemail_errorsto') { - $object->email_errorsto = trim(GETPOST('email_errorsto', 'alpha')); - } elseif ($action == 'settitle' && empty($object->title)) { + elseif ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from', 'none')); // Must allow 'name ' + elseif ($action == 'setemail_replyto') $object->email_replyto = trim(GETPOST('email_replyto', 'none')); // Must allow 'name ' + elseif ($action == 'setemail_errorsto') $object->email_errorsto = trim(GETPOST('email_errorsto', 'none')); // Must allow 'name ' + elseif ($action == 'settitle' && empty($object->title)) { $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle")); } elseif ($action == 'setfrom' && empty($object->email_from)) { $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom")); @@ -711,7 +710,7 @@ if ($action == 'create') dol_fiche_head(); print ''; - print ''; + print ''; print ''; print ''; @@ -868,7 +867,11 @@ if ($action == 'create') if ($email && !isValidEmail($email)) { $langs->load("errors"); print img_warning($langs->trans("ErrorBadEMail", $email)); + } elseif ($email && !isValidMailDomain($email)) { + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadMXDomain", $email)); } + print ''; // Errors to @@ -880,6 +883,9 @@ if ($action == 'create') if ($email && !isValidEmail($email)) { $langs->load("errors"); print img_warning($langs->trans("ErrorBadEMail", $email)); + } elseif ($email && !isValidMailDomain($email)) { + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadMXDomain", $email)); } print ''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 54cd54dccbe..2f4b3883819 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -629,6 +629,9 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = case 'san_alpha': $out = filter_var($out, FILTER_SANITIZE_STRING); break; + case 'email': + $out = filter_var($out, FILTER_SANITIZE_EMAIL); + break; case 'aZ': if (!is_array($out)) { @@ -2284,7 +2287,7 @@ function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0) } /** - * Show EMail link + * Show EMail link formatted for HTML output. * * @param string $email EMail to show (only email, without 'Name of recipient' before) * @param int $cid Id of contact if known @@ -2299,7 +2302,7 @@ function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, { global $conf, $user, $langs, $hookmanager; - $newemail = $email; + $newemail = dol_escape_htmltag($email); if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0; @@ -2936,11 +2939,12 @@ function dol_print_address($address, $htmlid, $element, $id, $noprint = 0, $char /** - * Return true if email syntax is ok + * Return true if email syntax is ok. * * @param string $address email (Ex: "toto@examle.com", "John Do ") * @param int $acceptsupervisorkey If 1, the special string '__SUPERVISOREMAIL__' is also accepted as valid * @return boolean true if email syntax is OK, false if KO or empty string + * @see isValidMXRecord() */ function isValidEmail($address, $acceptsupervisorkey = 0) { @@ -2956,6 +2960,7 @@ function isValidEmail($address, $acceptsupervisorkey = 0) * * @param string $domain Domain name (Ex: "yahoo.com", "yhaoo.com", "dolibarr.fr") * @return int -1 if error (function not available), 0=Not valid, 1=Valid + * @see isValidEmail() */ function isValidMXRecord($domain) { diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index a638d2c5745..16e31608941 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -484,15 +484,15 @@ function dolAddEmailTrackId($email, $trackingid) } /** - * Return true if email has a domain name that can't be resolved + * Return true if email has a domain name that can be resolved to MX type. * * @param string $mail Email address (Ex: "toto@example.com", "John Do ") - * @return boolean True if domain email is OK, False if KO + * @return int -1 if error (function not available), 0=Not valid, 1=Valid */ function isValidMailDomain($mail) { list($user, $domain) = explode("@", $mail, 2); - return checkdnsrr($domain, "MX"); + return ($domain ? isValidMXRecord($domain, "MX") : 0); } /** diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 47568f574fa..700a76e32a5 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -5,6 +5,7 @@ NoErrorCommitIsDone=No error, we commit # Errors ErrorButCommitIsDone=Errors found but we validate despite this ErrorBadEMail=Email %s is wrong +ErrorBadMXDomain=Email %s seems wrong (domain has no valid MX record) ErrorBadUrl=Url %s is wrong ErrorBadValueForParamNotAString=Bad value for your parameter. It appends generally when translation is missing. ErrorLoginAlreadyExists=Login %s already exists.
'.$langs->trans("MailTitle").'
'.$langs->trans("MailTitle").'
'.$langs->trans("MailFrom").'
'.$langs->trans("MailErrorsTo").'