Sending email with the application

I have a custom form (created using the forms API) that should send the downloaded file by email. The current form submission handler sends an email without an attachment using drupal_mail () .

So, I am looking for a solution for sending emails from Drupal correctly. Mime Mail seems redundant because HTML mail, templates, and other features are not required. But the only alternative that I see is setting the appropriate headers and serializing the attached file in the body of the message when processing mail in the hook_mail () implementation.

Did I miss something? Is there any module for this?

+5
source share
6 answers

Mimemail is the easiest solution here. Whether too much or not, this will allow you to do this with a single function call.

If you insist, you can have your home sender of attachments : base64 encodes your attachments, add them to the body of the message, add the correct headers, and you're done.

+3
source

You can use mime mail and force send the body of the message in text format. Here is an excerpt from the readme file of the module:

   ,    .    mimemail():

$sender - a user object, text email address or an array with name, mail
$recipient - a user object, text email address or an array with name, mail
$subject - subject line
$body - body text in HTML format
$plaintext - boolean, whether to send messages in plaintext-only (default FALSE)
$headers - a keyed array with headers (optional)
$text - plaintext portion of a multipart e-mail (optional)
$attachments - array of arrays with the file path, MIME type (optional)
$mailkey - message identifier

return - an array containing the MIME encoded message

- $plaintext TRUE. .

+1

Webform , . .

Webform . , , .

"", , "email" ( ) , , , .

0

Zend Framework.

function sendEmail($params){
    ini_set('include_path', 'inc/');
    require_once ('inc/Zend/Mail.php');

    $mail = new Zend_Mail();

    $mail->setSubject( $params['subject'] );

    $mail->setBodyText( $params['bodyText'] );
    $mail->setBodyHtml( $params['bodyHtml'] );

    $mail->setFrom( $params['fromEmail'], $params['fromName'] );
    $mail->addTo( $params['toEmail'], $params['toName'] );

    // Finally, add an attachment

    assert( file_exists($params['attachFile']) );

    $at = $mail->addAttachment(file_get_contents($params['attachFile']));
    $at->type        = $params['attachType'];
    $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
    $at->filename    = $params['attachName'];

    $mail->send();
}
0

Swift Mailer, (MIME), . HTML- , (HTML ).

Swift Mailer http://drupal.org/project/swiftmailer.

: .

0

I tried this solution and it works great! https://drupalium.com/articles/send-email-with-attachment-without-contrib-modules-drupal-8 there is no need to use a custom module :)

0
source

All Articles