답변:
magento에서 이메일을 보내는 간단한 기능
<?php
public function sendMailAction()
{
$html="
put your html content here
blah blah
";
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// You can use Html or text as Mail format
$mail->setBodyHTML($html); // your content or message
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
$this->_redirect('');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
$this->_redirect('');
}
}
?>
"거래 이메일"새 템플릿 양식을 작성하십시오.
hello {{var customerName}},
You received test template.
Thank you
새 템플릿을 작성한 후 참고 ID
컨트롤러 작업 생성
public function sendEnquiry()
{
$customer = Mage::getSingleton('customer/session')->getCustomer();
$templateId = 8; // Enter you new template ID
$senderName = Mage::getStoreConfig('trans_email/ident_support/name'); //Get Sender Name from Store Email Addresses
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email'); //Get Sender Email Id from Store Email Addresses
$sender = array('name' => $senderName,
'email' => $senderEmail);
// Set recepient information
$recepientEmail = $customer->getEmail();
$recepientName = $customer->getName();
// Get Store ID
$store = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('customerName' => $customer->getName());
// Send Transactional Email
Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
Mage::getSingleton('core/session')->addSuccess($this->__('We Will Contact You Very Soon.'));
}
이제 "트랜잭션 이메일"관리자를 사용하여 간단한 메일을 보낼 수 있습니다.
your_form.phtml 팔로우
<form action="<?php echo $this->getUrl("your_module_name/index/sendEnquiry")?>" id="discuss" method="post">
//Your form
</form>
이 코드를 시도하고 그에 따라 조정하십시오
$email_template = Mage::getModel('core/email_template')
->loadDefault($template_id);
/* load template by id */
$email_template_variables = array(
'customer_name' => $customer_name);
$sender_email = 'Info@yourCompany.com';
$sender_name = 'Your Friend at The Company';
$email_template->setSenderName($sender_name);
$email_template->setSenderEmail($sender_email);
$email_template->send(
$email_to, $customer_name,$email_template_variables
);
기본 (별도의 PHP 스크립트에서 작동해야 함). 예외없이 작동했지만 메일을받지 못했습니다. 그래서 SMTP 설정에 더 많은 시간을 보냈습니다.
// do not forget to include Mage.php before that
Mage::app();
// send email
$mail = Mage::getModel('core/email')
->setToEmail('<my email>')
->setBody('Body')
->setSubject('Subject:'.date("Y-m-d H:i:s"))
->setFromEmail('<from email>')
->setFromName('Magento Store Admin')
->setType('html');
$mail->send();
전제 조건 :
Magento 메일 설정이 localhost ( 시스템-> 구성-> 시스템-> 메일 전송 설정 ) 로 설정되었습니다.
SMTP가 작동하는지 확인하십시오 (로컬 호스트에서 CentOS에 telnet "yum install telnet"을 설치해야 할 수도 있음)
telnet localhost 25
MAIL FROM: <put from mail>
RCPT TO: <put to mail>
data:
Subject: <put your subject>
<Put body here>
.
QUIT
작동하지 않으면 SMTP를 구성하십시오. CentOS에서 postfix가 실행되고있었습니다
ps aux | grep posfix
vi로 설정을 편집했습니다.
vi /etc/postfix/main.cf
myhostname 만 설정하면 나를 위해 일했습니다.
PHP 메일 기능을 사용해보십시오 :
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// Send
$headers = 'From: <from mail>' . "\r\n" .
'Reply-To: <from mail>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail('<to mail>', 'My Subject', $message, $headers);
echo "<p>php mail sent 3</p>";
접미사의 경우 "mailq"를 입력하여 메일 대기열을 볼 수 있습니다