Php swift邮寄错误';Swift#u RFC符合例外情况';在一封真正有效的电子邮件上?

Php swift邮寄错误';Swift#u RFC符合例外情况';在一封真正有效的电子邮件上?,php,email,swiftmailer,Php,Email,Swiftmailer,我的swift mailer插件刚刚抛出了一个错误,因为它试图发送到的电子邮件地址不符合要求。问题是-电子邮件是有效的 基本上,我不希望swift mailer检查电子邮件是否有效,我希望它发送不管。可能吗 这是一段代码,它具有显示错误的功能,但我不知道我需要更改的内容是否在这里(有点像黑客程序员:|) /@require'Swift/Mime/Headers/AbstractHeader.php'; //@需要“Swift/Mime/headerncoder.php”; /** *类似“发件人

我的swift mailer插件刚刚抛出了一个错误,因为它试图发送到的电子邮件地址不符合要求。问题是-电子邮件是有效的

基本上,我不希望swift mailer检查电子邮件是否有效,我希望它发送不管。可能吗

这是一段代码,它具有显示错误的功能,但我不知道我需要更改的内容是否在这里(有点像黑客程序员:|)

/@require'Swift/Mime/Headers/AbstractHeader.php';
//@需要“Swift/Mime/headerncoder.php”;
/**
*类似“发件人”或“发件人”的邮箱地址MIME标头。
*@package Swift
*@subpackage Mime
*@作者克里斯·科尔宾
*/
类Swift\u Mime\u Headers\u MailboxHeader扩展了Swift\u Mime\u Headers\u AbstractHeader
{
/**
*此标头中使用的邮箱。
*@var字符串[]
*@access-private
*/
专用$_邮箱=数组();
/**
*使用$name创建新的MailboxHeader。
*@param string$Header的名称
*@param Swift\u Mime\u HeaderEncoder$encoder
*/
公共函数构造($name,Swift\u Mime\u HeaderEncoder$encoder)
{
$this->setFieldName($name);
$this->setEncoder($encoder);
$this->initializeGrammar();
}
/**
*获取此实例表示的标头类型。
*@return int
*@参见类型\文本,类型\参数化,类型\邮箱
*@参见类型\日期、类型\ ID、类型\路径
*/
公共函数getFieldType()
{
返回self::TYPE_邮箱;
}
/**
*设置字段主体的模型。
*此方法采用字符串或地址数组。
*@param混合$model
*@throws-Swift\u RfcComplianceException
*/
公共函数setFieldBodyModel($model)
{
$this->setNameAddresses($model);
}
/**
*获取字段实体的模型。
*此方法返回类似{@link getNameAddresses()}的关联数组
*@return数组
*@throws-Swift\u RfcComplianceException
*/
公共函数getFieldBodyModel()
{
返回$this->getNameAddresses();
}
/**
*设置要在此标头中显示的邮箱列表。
*邮箱可以是一个简单的地址数组,也可以是一个
*键=>值对,其中(电子邮件=>personalName)。
*例如:
*

* 
*
*@param string | string[]$mailboxs *@throws-Swift\u RfcComplianceException *@see__构造() *@see setAddresses() *@see setValue() */ 公共函数setNameAddresses($mailboxes) { $this->_mailboxs=$this->规范化邮箱((数组)$mailboxs); $this->setCachedValue(null);//清除任何缓存的值 } /** *以有效RFC 2822字符串数组的形式获取此标头的完整邮箱列表。 *例如: *

* 
*
*@returnstring[] *@throws-Swift\u RfcComplianceException *@请参阅getNameAddresses() *@see-toString() */ 公共函数getNameAddressString() { 返回$this->_createNameAddressString($this->getNameAddresses()); } /** *以键=>值对的形式获取此标头中的所有邮箱。 *键是地址,值是名称(如果未设置,则为null)。 *例如: *

* 
*
*@returnstring[] *@see getAddresses() *@请参阅getNameAddressStrings() */ 公共函数getNameAddresses() { 返回$this->\u邮箱; } /** *使此标题表示没有名称的普通电子邮件地址列表。 *例如: *

* 
*
*@param string[]$addresses *@throws-Swift\u RfcComplianceException *@请参阅setNameAddresses() *@see setValue() */ 公共函数setAddresses($addresses) { 返回$this->setNameAddresses(数组_值((数组)$addresses)); } /** *获取此标题中的所有电子邮件地址。 *@returnstring[] *@请参阅getNameAddresses() */ 公共函数getAddresses() { 返回数组\u键($this->\u邮箱); } /** *从此标头中删除一个或多个地址。 *@param string | string[]$地址 */ 公共函数removeAddresses($addresses) { $this->setCachedValue(null); foreach((数组)$地址作为$地址) { 取消设置($this->_邮箱[$address]); } } /** *获取此标头中正文的字符串值。 *这不一定符合RFC 2822,因为折叠空白将 *在此阶段不能添加(请参见{@link toString()})。 *@返回字符串 *@throws-Swift\u RfcComplianceException *@see-toString() */ 公共函数getFieldBody() { //仅在需要时计算标头的字符串值 如果(为空($this->getCachedValue()) { $this->setCachedValue($this->createMailboxListString($this->_邮箱)); } 返回$this->getCachedValue(); } //--扩展点 /** *将邮箱的用户输入列表规范化为一致的键=>值对。 *@param string[]$mailboxs *@returnstring[] *@访问受保护 */ 受保护的邮箱(阵列$mailboxes) { $actualmailboxs=array(); foreach($key=>$value的邮箱) { if(is_string($key))//key是email addr { $address=$key; $name=$value; } 其他的 { $address=$value; $name=null; } $this->_assertValidAddress($address); $actualmailboxs[$address]=$name; } 返回$actualmailboxs; } /** *根据给定的字符串生成符合要求的格式化显示名称。 *@param string$displayName显示为 *@param boolean$缩短第一行以删除标题名 *@返回字符串 *@访问受保护 */ 受保护的函数createDisplayNameString($displayName,$shorten=false) { 返回$this->createPhrase($this,$displayName, $this->getCharset(),$this->getEncoder(),$shorten ); } /** *创建所有邮箱的字符串形式
//@require 'Swift/Mime/Headers/AbstractHeader.php';
//@require 'Swift/Mime/HeaderEncoder.php';

/**
 * A Mailbox Address MIME Header for something like From or Sender.
 * @package Swift
 * @subpackage Mime
 * @author Chris Corbyn
 */
class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
{

  /**
   * The mailboxes used in this Header.
   * @var string[]
   * @access private
   */
  private $_mailboxes = array();

  /**
   * Creates a new MailboxHeader with $name.
   * @param string $name of Header
   * @param Swift_Mime_HeaderEncoder $encoder
   */
  public function __construct($name, Swift_Mime_HeaderEncoder $encoder)
  {
    $this->setFieldName($name);
    $this->setEncoder($encoder);
    $this->initializeGrammar();
  }

  /**
   * Get the type of Header that this instance represents.
   * @return int
   * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
   * @see TYPE_DATE, TYPE_ID, TYPE_PATH
   */
  public function getFieldType()
  {
    return self::TYPE_MAILBOX;
  }

  /**
   * Set the model for the field body.
   * This method takes a string, or an array of addresses.
   * @param mixed $model
   * @throws Swift_RfcComplianceException
   */
  public function setFieldBodyModel($model)
  {
    $this->setNameAddresses($model);
  }

  /**
   * Get the model for the field body.
   * This method returns an associative array like {@link getNameAddresses()}
   * @return array
   * @throws Swift_RfcComplianceException
   */
  public function getFieldBodyModel()
  {
    return $this->getNameAddresses();
  }

  /**
   * Set a list of mailboxes to be shown in this Header.
   * The mailboxes can be a simple array of addresses, or an array of
   * key=>value pairs where (email => personalName).
   * Example:
   * <code>
   * <?php
   * //Sets two mailboxes in the Header, one with a personal name
   * $header->setNameAddresses(array(
   *  'chris@swiftmailer.org' => 'Chris Corbyn',
   *  'mark@swiftmailer.org' //No associated personal name
   *  ));
   * ?>
   * </code>
   * @param string|string[] $mailboxes
   * @throws Swift_RfcComplianceException
   * @see __construct()
   * @see setAddresses()
   * @see setValue()
   */
  public function setNameAddresses($mailboxes)
  {
    $this->_mailboxes = $this->normalizeMailboxes((array) $mailboxes);
    $this->setCachedValue(null); //Clear any cached value
  }

  /**
   * Get the full mailbox list of this Header as an array of valid RFC 2822 strings.
   * Example:
   * <code>
   * <?php
   * $header = new Swift_Mime_Headers_MailboxHeader('From',
   *  array('chris@swiftmailer.org' => 'Chris Corbyn',
   *  'mark@swiftmailer.org' => 'Mark Corbyn')
   *  );
   * print_r($header->getNameAddressStrings());
   * // array (
   * // 0 => Chris Corbyn <chris@swiftmailer.org>,
   * // 1 => Mark Corbyn <mark@swiftmailer.org>
   * // )
   * ?>
   * </code>
   * @return string[]
   * @throws Swift_RfcComplianceException
   * @see getNameAddresses()
   * @see toString()
   */
  public function getNameAddressStrings()
  {
    return $this->_createNameAddressStrings($this->getNameAddresses());
  }

  /**
   * Get all mailboxes in this Header as key=>value pairs.
   * The key is the address and the value is the name (or null if none set).
   * Example:
   * <code>
   * <?php
   * $header = new Swift_Mime_Headers_MailboxHeader('From',
   *  array('chris@swiftmailer.org' => 'Chris Corbyn',
   *  'mark@swiftmailer.org' => 'Mark Corbyn')
   *  );
   * print_r($header->getNameAddresses());
   * // array (
   * // chris@swiftmailer.org => Chris Corbyn,
   * // mark@swiftmailer.org => Mark Corbyn
   * // )
   * ?>
   * </code>
   * @return string[]
   * @see getAddresses()
   * @see getNameAddressStrings()
   */
  public function getNameAddresses()
  {
    return $this->_mailboxes;
  }

  /**
   * Makes this Header represent a list of plain email addresses with no names.
   * Example:
   * <code>
   * <?php
   * //Sets three email addresses as the Header data
   * $header->setAddresses(
   *  array('one@domain.tld', 'two@domain.tld', 'three@domain.tld')
   *  );
   * ?>
   * </code>
   * @param string[] $addresses
   * @throws Swift_RfcComplianceException
   * @see setNameAddresses()
   * @see setValue()
   */
  public function setAddresses($addresses)
  {
    return $this->setNameAddresses(array_values((array) $addresses));
  }

  /**
   * Get all email addresses in this Header.
   * @return string[]
   * @see getNameAddresses()
   */
  public function getAddresses()
  {
    return array_keys($this->_mailboxes);
  }

  /**
   * Remove one or more addresses from this Header.
   * @param string|string[] $addresses
   */
  public function removeAddresses($addresses)
  {
    $this->setCachedValue(null);
    foreach ((array) $addresses as $address)
    {
      unset($this->_mailboxes[$address]);
    }
  }

  /**
   * Get the string value of the body in this Header.
   * This is not necessarily RFC 2822 compliant since folding white space will
   * not be added at this stage (see {@link toString()} for that).
   * @return string
   * @throws Swift_RfcComplianceException
   * @see toString()
   */
  public function getFieldBody()
  {
    //Compute the string value of the header only if needed
    if (is_null($this->getCachedValue()))
    {
      $this->setCachedValue($this->createMailboxListString($this->_mailboxes));
    }
    return $this->getCachedValue();
  }

  // -- Points of extension

  /**
   * Normalizes a user-input list of mailboxes into consistent key=>value pairs.
   * @param string[] $mailboxes
   * @return string[]
   * @access protected
   */
  protected function normalizeMailboxes(array $mailboxes)
  {
    $actualMailboxes = array();

    foreach ($mailboxes as $key => $value)
    {
      if (is_string($key)) //key is email addr
      {
        $address = $key;
        $name = $value;
      }
      else
      {
        $address = $value;
        $name = null;
      }
      $this->_assertValidAddress($address);
      $actualMailboxes[$address] = $name;
    }

    return $actualMailboxes;
  }

  /**
   * Produces a compliant, formatted display-name based on the string given.
   * @param string $displayName as displayed
   * @param boolean $shorten the first line to make remove for header name
   * @return string
   * @access protected
   */
  protected function createDisplayNameString($displayName, $shorten = false)
  {
    return $this->createPhrase($this, $displayName,
      $this->getCharset(), $this->getEncoder(), $shorten
      );
  }

  /**
   * Creates a string form of all the mailboxes in the passed array.
   * @param string[] $mailboxes
   * @return string
   * @throws Swift_RfcComplianceException
   * @access protected
   */
  protected function createMailboxListString(array $mailboxes)
  {
    return implode(', ', $this->_createNameAddressStrings($mailboxes));
  }

  // -- Private methods

  /**
   * Return an array of strings conforming the the name-addr spec of RFC 2822.
   * @param string[] $mailboxes
   * @return string[]
   * @access private
   */
  private function _createNameAddressStrings(array $mailboxes)
  {
    $strings = array();

    foreach ($mailboxes as $email => $name)
    {
      $mailboxStr = $email;
      if (!is_null($name))
      {
        $nameStr = $this->createDisplayNameString($name, empty($strings));
        $mailboxStr = $nameStr . ' <' . $mailboxStr . '>';
      }
      $strings[] = $mailboxStr;
    }

    return $strings;
  }

  /**
   * Throws an Exception if the address passed does not comply with RFC 2822.
   * @param string $address
   * @throws Exception If invalid.
   * @access protected
   */
  private function _assertValidAddress($address)
  {
    if (!preg_match('/^' . $this->getGrammar('addr-spec') . '$/D',
      $address))
    {
      throw new Swift_RfcComplianceException(
        'Address in mailbox given [' . $address .
        '] does not comply with RFC 2822, 3.6.2.'
        );
    }
  }

}
private function _assertValidAddress($address)
{
  if (!preg_match('/^' . $this->getGrammar('addr-spec') . '$/D',
    $address))
  {
    //throw new Swift_RfcComplianceException(
    //  'Address in mailbox given [' . $address .
    //  '] does not comply with RFC 2822, 3.6.2.'
    //  );
  }
}
  private function _assertValidAddress($address){
    if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D',
    $address))
  {
    //throw new Swift_RfcComplianceException(
    //  'Address in mailbox given [' . $address .
    //  '] does not comply with RFC 2822, 3.6.2.'
    //  );
  }
}
<?php
// Explosiveentertainment.co.uk //halal.cc 
include_once "lib/swift_required.php";

/*
 * Create the body of the message (a plain-text and an HTML version).
 * $text is your plain-text email
 * $html is your html version of the email
 * If the reciever is able to view html emails then only the html
 * email will be displayed
 */
$text = "Hi!\nHow are you?\n";
$html = <<<EOM
<html>
  <head></head>
  <body>
    <p>Hi!<br>
       How are you?<br>
    </p>
  </body>
</html>
EOM;


// This is your From email address
$from = array('yourcompany@yourcompany.com' => 'Name To Appear');
// Email recipients
$to = array(
  'destination1@example.com'=>'Destination 1 Name',
  'destination2@example.com'=>'Destination 2 Name'
);
// Email subject
$subject = 'Example PHP Email';

// Login credentials
$username = 'yoursendgridusername';
$password = 'yourpassword';

// Setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);

// Create a message (subject)
$message = new Swift_Message($subject);

// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');

// send message
if ($recipients = $swift->send($message, $failures))
{
  // This will let us know how many users received this message
  echo 'Message sent out to '.$recipients.' users';
}
// something went wrong =(
else
{
  echo "Something went wrong - ";
  print_r($failures);
}