本文整理汇总了PHP中Email::validEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::validEmailAddress方法的具体用法?PHP Email::validEmailAddress怎么用?PHP Email::validEmailAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Email
的用法示例。
在下文中一共展示了Email::validEmailAddress方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate()
{
$result = parent::validate();
if (empty($this->Email)) {
$result->error(_t('Newsletter.FieldRequired', '"{field}" field is required', array('field' => 'Email')));
}
if (!Email::validEmailAddress($this->Email)) {
$result->error(_t('Newsletter.InvalidEmailAddress', '"{field}" field is invalid', array('field' => 'Email')));
}
return $result;
}
示例2: validateEmailAddresses
protected function validateEmailAddresses($emails)
{
if (!empty($emails)) {
$recipients = preg_split("/\r\n|\n|\r/", $emails);
foreach ($recipients as $recipient) {
if (!Email::validEmailAddress($recipient)) {
return FALSE;
}
}
}
return TRUE;
}
示例3: testValidEmailAddress
public function testValidEmailAddress()
{
$validEmails = array('test@example.com', 'test-123@example.sub.com');
$invalidEmails = array('foo.bar@', '@example.com', 'foo@');
foreach ($validEmails as $email) {
$this->assertEquals($email, Email::validEmailAddress($email), 'validEmailAddress() returns a valid email address');
$this->assertEquals(1, Email::is_valid_address($email), 'is_valid_address() returns 1 for a valid email address');
}
foreach ($invalidEmails as $email) {
$this->assertFalse(Email::validEmailAddress($email), 'validEmailAddress() returns false for an invalid email address');
$this->assertEquals(0, Email::is_valid_address($email), 'is_valid_address() returns 0 for an invalid email address');
}
}
示例4: updateFacebookFields
/**
* Sync the new data from a users Facebook profile to the member database.
*
* @param Facebook\GraphUser $result
* @param bool $sync Flag to whether we override fields like first name
*/
public function updateFacebookFields($result, $override = true)
{
$this->owner->FacebookLink = $result->getProperty('link');
$this->owner->FacebookUID = $result->getProperty('id');
$this->owner->FacebookTimezone = $result->getProperty('timezone');
if ($override) {
$email = $result->getProperty('email');
if ($email && !$this->owner->Email || !Email::validEmailAddress($this->owner->Email)) {
$this->owner->Email = $email;
}
$this->owner->FirstName = $result->getProperty('first_name');
$this->owner->Surname = $result->getProperty('last_name');
}
$this->owner->extend('onUpdateFacebookFields', $result);
}
示例5: updateVkFields
/**
* Sync the new data from a users Vk profile to the member database.
*
* @param mixed $result
* @param bool $sync Flag to whether we override fields like first name
*/
public function updateVkFields($result, $override = true)
{
/** @var Member $member */
$member = $this->owner;
$member->VkUID = $result->uid;
if ($override) {
/** @var stdClass $session */
$session = Session::get(VkControllerExtension::VK_ACCESS_TOKEN);
$email = $session->email;
if ($email && !$this->owner->Email || !Email::validEmailAddress($this->owner->Email)) {
$member->Email = $email;
}
$member->FirstName = $member->FirstName ?: $result->first_name;
$member->Surname = $member->Surname ?: $result->last_name;
$member->VkTimezone = $member->VkTimezone ?: $result->timezone;
}
$member->extend('onUpdateVkFields', $result);
}
示例6: authenticate
/**
* Performs the login, but will also create and sync the Member record on-the-fly, if not found.
*
* @param array $data
* @param Form $form
* @return bool|Member|void
* @throws SS_HTTPResponse_Exception
*/
public static function authenticate($data, Form $form = null)
{
$service = Injector::inst()->get('LDAPService');
$login = trim($data['Login']);
if (Email::validEmailAddress($login)) {
if (Config::inst()->get('LDAPAuthenticator', 'allow_email_login') != 'yes') {
$form->sessionMessage(_t('LDAPAuthenticator.PLEASEUSEUSERNAME', 'Please enter your username instead of your email to log in.'), 'bad');
return;
}
$username = $service->getUsernameByEmail($login);
// No user found with this email.
if (!$username) {
$form->sessionMessage(_t('LDAPAuthenticator.INVALIDCREDENTIALS', 'Invalid credentials'), 'bad');
return;
}
} else {
$username = $login;
}
$result = $service->authenticate($username, $data['Password']);
$success = $result['success'] === true;
if (!$success) {
if ($form) {
$form->sessionMessage($result['message'], 'bad');
}
return;
}
$data = $service->getUserByUsername($result['identity']);
if (!$data) {
if ($form) {
$form->sessionMessage(_t('LDAPAuthenticator.PROBLEMFINDINGDATA', 'There was a problem retrieving your user data'), 'bad');
}
return;
}
// LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields
$member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
if (!($member && $member->exists())) {
$member = new Member();
$member->GUID = $data['objectguid'];
$member->write();
}
Session::clear('BackURL');
return $member;
}
示例7: sendTempPasswordEmail
/**
* Send temporary password to user via email.
*/
public function sendTempPasswordEmail($template = null, $subject = null, $extradata = null)
{
//set expiry
$template = $template ? $template : 'TempPasswordEmail';
$subject = $subject ? $subject : "Temporary Password";
$data = array('CleartextTempPassword' => $this->owner->setupTempPassword());
if ($extradata) {
$data = array_merge($data, $extradata);
}
$body = $this->owner->customise($data)->renderWith($template);
if (Email::validEmailAddress($this->owner->Email)) {
$email = new Email(Email::getAdminEmail(), $this->owner->Email, $subject, $body);
if ($email->send()) {
return true;
}
return false;
}
return false;
}
示例8: index
function index($request)
{
if (!Permission::check("ADMIN")) {
return Security::permissionFailure($this);
}
$email = $request->requestVar($name = "email");
if ($email && Email::validEmailAddress($email)) {
$number = rand(0, 10000);
$from = Email::getAdminEmail();
$to = $email;
$subject = "test mail ID" . $number;
$body = "test mail ID" . $number;
$htmlBody = "<h1>test mail ID" . $number . '</h1>';
$basicMailOk = @mail($email, $subject, $body);
if ($basicMailOk) {
DB::alteration_message("basic mail (using the PHP mail function) has been sent with ID: " . $number, "created");
} else {
DB::alteration_message("basic mail (using the PHP mail function) has * NOT * been sent with ID:" . $number, "deleted");
}
$e = new Email($from, $to, $subject, $body);
if ($e->send()) {
DB::alteration_message("standard Silverstripe email has been sent with ID: " . $number, "created");
} else {
DB::alteration_message("standard Silverstripe email ***NOT*** has been sent with ID: " . $number, "deleted");
}
//OR
$e = new Email($from, $to, $subject, $body);
if ($e->sendPlain()) {
DB::alteration_message("plain text Silverstripe email has been sent with ID: " . $number, "created");
} else {
DB::alteration_message("plain text Silverstripe email has ***NOT*** been sent with ID: " . $number, "deleted");
}
} else {
user_error("make sure to add a valid email - current one is '" . $email . "' (you can add the email like this: " . $request->getURL() . "?email=myemail@test.com", E_USER_WARNING);
}
}
示例9: forgotPassword
/**
* Forgot password form handler method.
*
* Called when the user clicks on "I've lost my password".
*
* Extensions can use the 'forgotPassword' method to veto executing
* the logic, by returning FALSE. In this case, the user will be redirected back
* to the form without further action. It is recommended to set a message
* in the form detailing why the action was denied.
*
* Overridden because we need to generate a link to the LDAPSecurityController
* instead of the SecurityController
*
* @param array $data Submitted data
* @return SS_HTTPResponse
*/
public function forgotPassword($data)
{
// No need to protect against injections, LDAPService will ensure that this is safe
$login = trim($data['Login']);
$service = Injector::inst()->get('LDAPService');
if (Email::validEmailAddress($login)) {
if (Config::inst()->get('LDAPAuthenticator', 'allow_email_login') != 'yes') {
$this->sessionMessage(_t('LDAPLoginForm.USERNAMEINSTEADOFEMAIL', 'Please enter your username instead of your email to get a password reset link.'), 'bad');
$this->controller->redirect($this->controller->Link('lostpassword'));
return;
}
$userData = $service->getUserByEmail($login);
} else {
$userData = $service->getUserByUsername($login);
}
// Avoid information disclosure by displaying the same status,
// regardless whether the email address actually exists
if (!isset($userData['objectguid'])) {
return $this->controller->redirect($this->controller->Link('passwordsent/') . urlencode($data['Login']));
}
$member = Member::get()->filter('GUID', $userData['objectguid'])->limit(1)->first();
// User haven't been imported yet so do that now
if (!($member && $member->exists())) {
$member = new Member();
$member->GUID = $userData['objectguid'];
$member->write();
}
// Allow vetoing forgot password requests
$results = $this->extend('forgotPassword', $member);
if ($results && is_array($results) && in_array(false, $results, true)) {
return $this->controller->redirect($this->ldapSecController->Link('lostpassword'));
}
// update the users from LDAP so we are sure that the email is correct
$service->updateMemberFromLDAP($member);
if ($member) {
$token = $member->generateAutologinTokenAndStoreHash();
$e = Member_ForgotPasswordEmail::create();
$e->populateTemplate($member);
$e->populateTemplate(array('PasswordResetLink' => LDAPSecurityController::getPasswordResetLink($member, $token)));
$e->setTo($member->Email);
$e->send();
$this->controller->redirect($this->controller->Link('passwordsent/') . urlencode($data['Login']));
} elseif ($data['Login']) {
// Avoid information disclosure by displaying the same status,
// regardless whether the email address actually exists
$this->controller->redirect($this->controller->Link('passwordsent/') . urlencode($data['Login']));
} else {
if (Config::inst()->get('LDAPAuthenticator', 'allow_email_login') === 'yes') {
$this->sessionMessage(_t('LDAPLoginForm.ENTERUSERNAMEOREMAIL', 'Please enter your username or your email address to get a password reset link.'), 'bad');
} else {
$this->sessionMessage(_t('LDAPLoginForm.ENTERUSERNAME', 'Please enter your username to get a password reset link.'), 'bad');
}
$this->controller->redirect($this->controller->Link('lostpassword'));
}
}
示例10: SendEnquiryForm
public function SendEnquiryForm($data, $form)
{
$From = $this->EmailFrom;
$To = $this->EmailTo;
$Subject = $this->EmailSubject;
$email = new Email($From, $To, $Subject);
$replyTo = $this->EnquiryFormFields()->filter(array('FieldType' => 'Email'))->First();
if ($replyTo) {
$postField = $this->keyGen($replyTo->FieldName, $replyTo->SortOrder);
if (isset($data[$postField]) && Email::validEmailAddress($data[$postField])) {
$email->replyTo($data[$postField]);
}
}
if ($this->EmailBcc) {
$email->setBcc($this->EmailBcc);
}
//abuse / tracking
$email->addCustomHeader('X-Sender-IP', $_SERVER['REMOTE_ADDR']);
//set template
$email->setTemplate('EnquiryFormEmail');
//populate template
$templateData = $this->getTemplateData($data);
$email->populateTemplate($templateData);
//send mail
$email->send();
//return to submitted message
if (Director::is_ajax()) {
return $this->renderWith('EnquiryPageAjaxSuccess');
}
$this->redirect($this->Link('?success=1#thankyou'));
}
示例11: send
/**
* sends email to defined address
*
* @param string $identifier identifier for email template
* @param string $to recipients email address
* @param array $variables array with template variables that can be called in the template
* @param array $attachments absolute filename to an attachment file
*
* @return bool
*
* @author Sebastian Diel <sdiel@pixeltricks.de>,
* Sascha Koehler <skoehler@pixeltricks.de>
* @since 16.06.2014
*/
public static function send($identifier, $to, $variables = array(), $attachments = null)
{
$mailObj = SilvercartShopEmail::get()->filter('Identifier', $identifier)->first();
if (!$mailObj) {
return false;
}
$emailText = trim($mailObj->EmailText);
if (is_null($emailText) || empty($emailText)) {
return false;
}
$emailSubject = trim($mailObj->Subject);
if (is_null($emailSubject) || empty($emailSubject)) {
return false;
}
if (!is_array($variables)) {
$variables = array();
}
$templateVariables = new ArrayData($variables);
$emailTextTemplate = new SSViewer_FromString($mailObj->EmailText);
$emailText = HTTP::absoluteURLs($emailTextTemplate->process($templateVariables));
$emailSubjectTemplate = new SSViewer_FromString($mailObj->Subject);
$emailSubject = HTTP::absoluteURLs($emailSubjectTemplate->process($templateVariables));
$email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
$email->setTemplate('SilvercartShopEmail');
$email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
self::attachFiles($email, $attachments);
$email->send();
if (SilvercartConfig::GlobalEmailRecipient() != '') {
$email = new Email(SilvercartConfig::EmailSender(), SilvercartConfig::GlobalEmailRecipient(), $emailSubject, $mailObj->EmailText);
$email->setTemplate('SilvercartShopEmail');
$email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
$email->send();
}
//Send the email to additional standard receipients from the n:m
//relation AdditionalReceipients;
//Email address is validated.
if ($mailObj->AdditionalReceipients()->exists()) {
foreach ($mailObj->AdditionalReceipients() as $additionalReceipient) {
if ($additionalReceipient->getEmailAddressWithName() && Email::validEmailAddress($additionalReceipient->Email)) {
$to = $additionalReceipient->getEmailAddressWithName();
} elseif ($additionalReceipient->getEmailAddress() && Email::validEmailAddress($additionalReceipient->Email)) {
$to = $additionalReceipient->getEmailAddress();
} else {
continue;
}
$email = new Email(SilvercartConfig::EmailSender(), $to, $emailSubject, $mailObj->EmailText);
$email->setTemplate('SilvercartShopEmail');
$email->populateTemplate(array('ShopEmailSubject' => $emailSubject, 'ShopEmailMessage' => $emailText));
self::attachFiles($email, $attachments);
$email->send();
}
}
}
示例12: getEmailTo
private function getEmailTo($data)
{
$recipient_field = $this->RecipientMapField;
$recipient_map = $this->RecipientMap;
if (isset($data[$recipient_field])) {
$lines = explode("\n", $recipient_map);
foreach ($lines as $line) {
$value = explode(':', $line);
var_dump($value);
if ($value[0] == $data[$recipient_field]) {
if (Email::validEmailAddress(trim($value[1]))) {
return trim($value[1]);
}
}
}
}
return $this->DefaultRecipient;
}
示例13: connectFacebookAccount
/**
* This connects the given facebook account to the current DataObject
*
* @param $user array - data rutned by calling $facebook->api("/me");
* @param $access_token string - Facebook User Access Token
* @param $required_fields array - fields that should exist within the array.
*
* @return ValidationResult
**/
public function connectFacebookAccount($user, $access_token, $required_fields = array())
{
$validation = new ValidationResult();
// Check required fields exist.
$required = array_merge($required_fields, array("id"));
foreach ($required as $r) {
if (!isset($user[$r])) {
$validation->error("A required fields was missing: " . $r);
return $validation;
}
}
// Write our values to the DataObject
$this->owner->FacebookUserID = $user['id'];
// Required field.
$this->owner->FacebookAccessToken = $access_token;
if (isset($user['email']) && !$this->owner->Email && Email::validEmailAddress($user['email'])) {
$this->owner->Email = $user['email'];
}
if (isset($user['first_name']) && !$this->owner->FirstName) {
$this->owner->FirstName = $user['first_name'];
}
if (isset($user['last_name']) && !$this->owner->Surname) {
$this->owner->Surname = $user['last_name'];
}
// Facebook hook
$this->owner->extend("beforeConnectFacebookAccount", $validation, $user, $access_token);
$memberValidation = $this->owner->validate();
if ($memberValidation->valid()) {
if (!$this->owner->write()) {
$validation->error("Unable to create your account.");
}
} else {
$this->owner->extend("invalidFacebookConnect", $memberValidation);
return $memberValidation;
}
return $validation;
}
示例14: buildBasicMail
/**
* @param string $to
* @param string $from
* @param string $subject
* @return void
*/
protected function buildBasicMail($to, $from, $subject)
{
if (preg_match('/(\'|")(.*?)\\1[ ]+<[ ]*(.*?)[ ]*>/', $from, $from_splitted)) {
// If $from countain a name, e.g. "My Name" <me@acme.com>
$this->mailer->SetFrom($from_splitted[3], $from_splitted[2]);
} else {
$this->mailer->SetFrom($from);
}
// not entirely sure what this will do
if (!Email::validEmailAddress($to)) {
$to = false;
}
$this->mailer->ClearAddresses();
$this->mailer->AddAddress($to, ucfirst(substr($to, 0, strpos($to, '@'))));
// For the recipient's name, the string before the @ from the e-mail address is used
$this->mailer->Subject = $subject;
}