2011-02-28 15 views
0

は私のお問い合わせモジュールで、drupalの電子メールの問題以下

はあなたが呼んでいる私のスニペットで間違い

<?php 

function contactus_menu() { 
    $items['contactus/reachus'] = array(
    'title' => 'Contact US', 
    'page callback' => 'contactus_description', 
    'access callback' => TRUE, 
    'expanded' => TRUE, 
); 

    return $items; 
} 

    function contactus_description(){ 

    return drupal_get_form('contactus_form'); 
} 

function contactus_form() { 
$form['#attributes']['enctype'] = 'multipart/form-data'; 
    $form['fullname'] = array(
    '#type' => 'textfield', 
    '#title' => t('Enter your full name'), 
    '#description' => t('Please enter your name here'), 
    '#required' => TRUE, 
); 
    $form['emailid'] = array(
    '#type' => 'textfield', 
    '#title' => t('Enter your Email-ID'), 
    '#description' => t('Please enter your Email-ID'), 
    '#required' => TRUE, 
); 
    $form['message'] = array(
    '#type' => 'textarea', 
    '#title' => t('Enter your message'), 
    '#default_value' => variable_get('Please enter your message', ''), 
    '#cols' => 60, 
    '#rows' => 5, 
    '#description' => t('Please write your mssage'), 
); 
    $form['file_upload'] = array(
    '#title' => t('Upload file'), 
    '#required' => TRUE, 
    '#type' => 'file', 
); 
    $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Reach Me '), 
); 
    return $form; 
} 

function contactus_form_submit($form_id, $form_values) { 
    $message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r($form_values,true) . '</pre>'; 
    $fullname = $form_values['values']['fullname']; 
    $emailid = $form_values['values']['emailid']; 
    $email_flag = valid_email_address($emailid); 

    $message = $form_values['values']['message']; 
    $message = $fullname . "\n" .$emailid. "\n" .$message; 

    $validators = array(); 
    $dest = 'file'; 
    $file = file_save_upload('file_upload', $validators, $dest); 
    //$file will be 0 if the upload doesn't exist, or the $dest directory 
    //isn't writable 
    if ($file != 0) { 
    $dest_path = 'contactus'; 
    $result = file_copy($file, $dest_path, FILE_EXISTS_RENAME); 
    if ($result == 1) { 
     //Success, $file object will contain a different (renamed) 
     //filename and filepath if the destination existed 

     $file_msg = "successfully uploaded\n"; 
    } 
    else { 
     //Failure 
     $file_msg = "failed uploaded\n"; 
    } 
    } 
    else { 
    form_set_error('myform', t("Failed to save the file.")); 
    } 
    $message = $fullname."\n".$emailid." ---$email_flag ----\n".$message."\n".$file_msg; 
    $to = '[email protected]'; 
    $from = '[email protected]'; 
    $subject = st('New Drupal site created!'); 

drupal_mail('university-profile', $to, $subject, $message, $from); 
} 

?> 
+0

ウォッチドッグログ([レポート]> [最近のログエントリ])でエラーを確認しましたか? mailqにエラーがないかチェックしましたか? http://linux.about.com/library/cmd/blcmdl1_mailq.htm –

答えて

0

があり、推測メールが正常に送信していない、電子メールを送信しようとしていますdrupal_mailに間違ったパラメータがあります。 Drupalでメールを送信する正しい方法は、あなたがキーとdrupal_mailによって送信されたいくつかのパラメータに基づいて、電子メールのタイトルと件名を返すhook_mailフックを実装する必要があります。

簡単な例についてはこちらをご覧ください:しかし、あなたはこれを使用することができますdrupal_mailスキップしたい、場合http://api.lullabot.com/drupal_mail

<?php 
    $message = array(
     'to' => '[email protected]', 
     'subject' => t('Example subject'), 
     'body' => t('Example body'), 
     'headers' => array('From' => '[email protected]'), 
    ); 

    drupal_mail_send($message); 

をあなたがトンを介してすべてのテキストを(パスを確認してください)以来drupal_mail_sendはローカライゼーションを行いません。

+0

これでN長メール本文を送信できますか?添付ファイルの追加方法 – Bharanikumar

関連する問題