나는 그것이 유용 sfActions를 확장하는 기본 클래스에서 보내는 코드를 넣어 찾을 수 있습니다. 일반적으로 프로젝트 전반에 걸쳐 사용되는 모든 것을 던져 버립니다 (아약스 사용에 도움이되는 코드 등).
특히 이메일, 나는 정적 메서드
public static function mail($options, $mailer) {
sfProjectConfiguration::getActive()->loadHelpers('Partial');
$required = array('subject', 'parameters', 'to_email', 'to_name', 'html', 'text');
foreach ($required as $option)
{
if (!isset($options[$option])) {
throw new sfException("Required option $option not supplied to ef3Actions::mail");
}
}
$address = array();
if (isset($options['from_name']) && isset($options['from_email'])) {
$address['fullname'] = $options['from_name'];
$address['email'] = $options['from_email'];
} else
$address = self::getFromAddress();
if(!isset($options['body_is_partial']) || $options['body_is_partial']==true){
$message = Swift_Message::newInstance()
->setFrom(array($address['email'] => $address['fullname']))
->setTo(array($options['to_email'] => $options['to_name']))
->setSubject($options['subject'])
->setBody(get_partial($options['html'], $options['parameters']), 'text/html')
->addPart(get_partial($options['text'], $options['parameters']), 'text/plain');
} else {
$message = Swift_Message::newInstance()
->setFrom(array($address['email'] => $address['fullname']))
->setTo(array($options['to_email'] => $options['to_name']))
->setSubject($options['subject'])
->setBody($options['html'], 'text/html')
->addPart($options['text'], 'text/plain');
}
if (isset($options['cc']) && !is_null($options['cc'])) {
if (is_array($options['cc'])) {
foreach ($options['cc'] as $key => $value) {
if (!is_number($key))
$message->addCc($key, $value);
else
$message->addCc($value);
}
} elseif (is_string($options['cc'])) {
$message->addCc($options['cc']);
}
}
if (isset($options['bcc']) && !is_null($options['bcc'])) {
if (is_array($options['bcc'])) {
foreach ($options['bcc'] as $key => $value) {
if (!is_number($key))
$message->addBcc($key, $value);
else
$message->addBcc($value);
}
} elseif (is_string($options['bcc'])) {
$message->addBcc($options['bcc']);
}
}
if (isset($options['attachments'])) {
$atts = $options['attachments'];
if (is_array($atts)) {
foreach ($atts as $att) {
$message->attach(Swift_Attachment::fromPath($att));
}
} elseif (is_string($atts)) {
$message->attach(Swift_Attachment::fromPath($atts));
}
}
try
{
return $mailer->send($message);
} catch (Exception $e)
{
throw new Exception("Erro ao tentar enviar um email: " . $e->getMessage());
}
}
왜 정적 방법 있나요? 음, 이벤트 리스너와 같은 다른 컨텍스트에서도이 메서드를 사용했습니다. 또한 이메일 (HTML 및 텍스트)의 두 버전을 보내는의 사용을 강제
// SEND EMAIL FROM ACTION
$opts = array();
$opts['from_name'] = 'Webmaster';
$opts['from_email'] = '[email protected]';
$variables = array();
// variables passed to the partial template
$variables['%client_firstname%'] = $firstName;
$variables['%client_lastname%'] = $lastName;
$variables['%client_email%'] = $client_email;
// preenche opcoes de envio
$opts['parameters'] = array();
$opts['body_is_partial'] = false;
$opts['to_name'] = $variables['%client_firstname%'] . " " . $variables['%client_lastname%'];
$opts['to_email'] = $variables['%client_email%'];
$opts['subject'] = __($subject, $variables);
$opts['html'] = __($message_html, $variables);
$opts['text'] = __($message_text, $variables);
if (isset($cc)) $opts['cc'] = $cc;
$bcc = sfDoctrineKeyValueProjectStore::get("{$contexto}_message_bcc");
if (isset($bcc)) $opts['bcc'] = $bcc;
return dcActions::mail($opts, sfContext::getInstance()->getMailer());
같은 이메일을 보내는 전형적인 전화 보인다. 이러한 코드를 사용하면 partial을 사용하여 전자 메일 메시지를 전달할 수도 있습니다. 나는 그것을 매우 유용하다고 느낀다.
감사합니다. 유용하지 않습니다. – craphunter