ฉันสร้างฟอร์มที่มีฟิลด์ป้อนข้อมูลบางส่วนใน Magento แต่เมื่อฉันคลิกส่งวีโอไอพีจะไม่ส่งอีเมล
ฉันจะส่งอีเมลพื้นฐานใน Magento ได้อย่างไร
ฉันสร้างฟอร์มที่มีฟิลด์ป้อนข้อมูลบางส่วนใน Magento แต่เมื่อฉันคลิกส่งวีโอไอพีจะไม่ส่งอีเมล
ฉันจะส่งอีเมลพื้นฐานใน 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
);สำหรับจดหมาย UTF-8:
$mail = new Zend_Mail('utf-8');
$mail->setFrom($senderEmail, $senderName);
$mail->addTo($toEmail, $toName);
$mail->setSubject($subject);
$mail->setBodyHTML($html); // Or plain: $mail->setBodyText($text)
$mail->send();พื้นฐาน (ควรทำงานในสคริปต์ 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(); วิชาบังคับก่อน:
การตั้งค่าเมลวีโอไอพีตั้งค่าเป็น localhost ( ระบบ -> การกำหนดค่า -> ระบบ -> การตั้งค่าการส่งเมล )
ตรวจสอบให้แน่ใจว่า SMTP ของคุณทำงาน (บนโลคัลโฮสต์ที่คุณสามารถตรวจสอบได้คุณอาจต้องติดตั้ง telnet "yum install telnet" บน CentOS)
telnet localhost 25
MAIL FROM: <put from mail>
RCPT TO: <put to mail>
data: 
Subject: <put your subject>
<Put body here>
. 
QUITถ้ามันไม่ทำงานกำหนดค่า SMTP มี postfix ที่ทำงานบน CentOS ของฉัน
 ps aux | grep posfixฉันแก้ไขการตั้งค่าด้วย vi:
     vi /etc/postfix/main.cfการตั้งค่าเพียง myhostname ใช้งานได้สำหรับฉัน
ลองใช้ฟังก์ชั่น mail 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>";สำหรับ postfix คุณสามารถดูคิวจดหมายที่พิมพ์ "mailq"