Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:19:47+00:00 2026-06-13T21:19:47+00:00

I am trying sending email with Drupal 7. The email is sent to my

  • 0

I am trying sending email with Drupal 7. The email is sent to my email account but somehow the body and subject is empty. Please help me to explain why. Thank you very much.

Below is my code:

This is the form

function get_friendform($form,&$form_submit){
    $form['fullname'] = array(
        '#title' => t('Your Full Name: '),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#size' => 30,
    );

    $form['email'] = array(
        '#title' => t('Your Full Email: '),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#size' => 30,
    );

    $form['friend_email'] = array(
        '#title' => t('Your Friend Email: '),
        '#type' => 'textfield',
        '#required' => TRUE,
        '#size' => 30,
    );


    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'submit',
        '#submit' => array('sendform_form_submit')

    );

    return $form;
}



function sendform_form_submit($form,&$form_submit){
    $fullname = $form_submit['values']['fullname'];
    $email = $form_submit['values']['email'];
    $friend_email = $form_submit['values']['friend_email'];
    $current_page = $GLOBALS['base_url'] .'/'.current_path();

    $mailto = 'thelinhuk@gmail.com';
    $mailfrom = 'thelinhuk@yahoo.com';
    $subject = "Links to event";
    $body = $current_page;
    $params = array(
        'body' => $body,
        'subject' => $subject,
    );

    if (drupal_mail('get_friendform', 'send_link', $mailto, language_default(),$params,$mailfrom,TRUE)) {
        drupal_set_message(t('Your message was sent successfully!!!'));
    }

}



function sendform_mail($key,&$message,$params) {
    $language = $message['language'];
    switch ($key) {
        case 'send_link':
            $message['subject']=t($params['subject'], $var, $language->language);
            $message['body'][]=$params['body'];
            $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
        break;
    }

}

Thank you very much

new code

function sendform_form_submit($form,&$form_submit){
    $fullname = $form_submit['values']['fullname'];
    $email = $form_submit['values']['email'];
    $friend_email = $form_submit['values']['friend_email'];
    $current_page = $GLOBALS['base_url'] .'/'.current_path();

    $mailto = 'thelinhuk@gmail.com';
    $mailfrom = 'thelinhuk@yahoo.com';
    $subject = "Links to event";
    $params ='';
    $body[] = $current_page;
    $mail_message = drupal_mail('send_form', 'some_key', $mailto, language_default(), $params, $mailfrom, TRUE);
    $mail_message['subject'] = $subject;
    $mail_message['body'] = $body;

    $mail_system = drupal_mail_system($module, $key);
    $mail_message = $mail_system->format($mail_message);

    $mail_message['result'] = $mail_system->mail($mail_message);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:19:50+00:00Added an answer on June 13, 2026 at 9:19 pm

    Use the following code example to send emails using drupal:

    $body = array();
    $body[] = "Mail body";
    $mail_message = drupal_mail($module, $key, $to, $lang, $params, $from, $send);
    $mail_message['subject'] = $subject;
    $mail_message['body'] = $body;
    
    $mail_system = drupal_mail_system($module, $key);
    $mail_message = $mail_system->format($mail_message);
    
    $mail_message['result'] = $mail_system->mail($mail_message);
    

    Update 1:

    There’s a problem in your code. You have created a function sendform_mail() and you never called it.

    You can use the code example above inside the form submission callback sendform_form_submit(). This is much simpler

    Update 2:

    $mail_message = drupal_mail('send_form', 'some_key', $mailto, language_default(), $params, $mailfrom, TRUE);
    

    In your code, change the last value to false, because you need to stall the mail sending till the last line $mail_message['result'].

    Hope this works… Muhammad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to testing sending email in my rails 3 app, and am
Possible Duplicate: Sending email in .NET through Gmail I am trying to send a
Sending Email in Android using JavaMail API without using the default/built-in app I'm trying
I've spent the past two days just trying to enable the sending of email
I am trying to send a faceless email (sending an email without showing the
for sending email i set server name smtp.mail.yahoo.com and port is 465 i trying
i am trying to avoid the wait time, taken by sending an email before
I am trying to open email sending form of Gmail directly on button click
I'm sending an email using the cfmail tag, and trying to attach a PDF
I'm trying to send email with Swiftmailer but it doesn't seem to be setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.