How to call php mail function from magento cms

In Magento, you can call the PHP mail() function from a CMS page using the following methods:

Method 1: Using the Mage::app()->getMail() method

You can use the Mage::app()->getMail() method to send an email using the PHP mail() function. Here's an example:

<?php
$mail = Mage::app()->getMail();
$mail->setTo('[email protected]');
$mail->setSubject('Test Email');
$mail->setBody('This is a test email');
$mail->send();
?>

Method 2: Using the Zend_Mail class

You can also use the Zend_Mail class to send an email using the PHP mail() function. Here's an example:

<?php
$mail = new Zend_Mail('text');
$mail->addTo('[email protected]');
$mail->setSubject('Test Email');
$mail->setBodyText('This is a test email');
$mail->send();
?>

Method 3: Using a custom PHP script

You can also create a custom PHP script that uses the mail() function and call it from your CMS page using the echo statement. Here's an example:

<?php
function send_email() {
    $to = '[email protected]';
    $subject = 'Test Email';
    $body = 'This is a test email';
    mail($to, $subject, $body);
}
send_email();
?>

Calling the PHP script from a CMS page

To call the PHP script from a CMS page, you need to add a PHP block to your CMS page and call the script using the echo statement. Here's an example:

  1. Go to System > Configuration > Advanced > Developer > PHP Settings and set allow_php_blocks to Yes.
  2. Go to CMS > Pages and edit the page where you want to add the PHP block.
  3. Click on the Insert Widget button and select PHP Block.
  4. In the PHP block, add the following code:
    <?php
    send_email();
    ?>
  5. Save the changes and refresh the page.

Note: Make sure to test your email sending code in a development environment before deploying it to a production environment.