Last active
May 25, 2017 15:38
-
-
Save EvilGoTa/58bd1874779f1195cfde7835e5c46aae to your computer and use it in GitHub Desktop.
Webasyst простая отправка email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function mailSend($to, &$errors) { | |
if (!$to) { | |
$app_settings_model = new waAppSettingsModel(); | |
$to = $app_settings_model->get('webasyst', 'email'); | |
} | |
if (!$to) { | |
$errors['all'] = _ws('Recipient (administrator) email is not valid'); | |
return false; | |
} | |
$email = waRequest::post('email'); | |
$email_validator = new waEmailValidator(); | |
$subject = trim(waRequest::post('subject', _ws('Website request'))); | |
$body = trim(waRequest::post('body')); | |
if (!$body) { | |
$errors['body'] = _ws('Please define your request'); | |
} | |
if (!$email) { | |
$errors['email'] = _ws('Email is required'); | |
} elseif (!$email_validator->isValid($email)) { | |
$errors['email'] = implode(', ', $email_validator->getErrors()); | |
} | |
if (!$errors) { | |
$body = nl2br(htmlspecialchars($body)); | |
$body = _ws('Name').': '.htmlspecialchars(waRequest::post('name'))."<br>\n". | |
_ws('Email').': '.htmlspecialchars($email)."<br><br>\n".$body; | |
$m = new waMailMessage($subject, $body); | |
$m->setTo($to); | |
$m->setReplyTo(array($email => waRequest::post('name'))); | |
// wa_dump($m, $subject, $body, $to); | |
if (!$m->send()) { | |
$errors['all'] = _ws('An error occurred while attempting to send your request. Please try again in a minute.'); | |
} else { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment