2010-02-11 29 views
0

我正在使用Prestashop作爲我的電子商務購物車和CMS解決方案,並且在接收通過聯繫表單發送的電子郵件時遇到問題。我四處詢問,發現問題是由於我需要將來自我的域名的「發件人」地址(例如[email protected])和用戶輸入的電子郵件分配給不同的變量(例如, 'replyemail')。重新配置PHP郵件()Smarty聯繫表

然而,的Prestashop接觸形式與PHP Smarty的模板引擎,它具有獨立的接觸form.php的文件和我下面顯示單獨的接觸form.tpl創建。 首先接觸form.php的: -

<?php 

$useSSL = true; 

include(dirname(__FILE__).'/config/config.inc.php'); 
include(dirname(__FILE__).'/header.php'); 

$errors = array(); 

$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang))); 

if (Tools::isSubmit('submitMessage')) 
{ 
    if (!($from = Tools::getValue('from')) OR !Validate::isEmail($from)) 
     $errors[] = Tools::displayError('invalid e-mail address'); 
    elseif (!($message = nl2br2(Tools::getValue('message')))) 
     $errors[] = Tools::displayError('message cannot be blank'); 
    elseif (!Validate::isMessage($message)) 
     $errors[] = Tools::displayError('invalid message'); 
    elseif (!($id_contact = intval(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang))))) 
     $errors[] = Tools::displayError('please select a contact in the list'); 
    else 
    { 
     if (intval($cookie->id_customer)) 
      $customer = new Customer(intval($cookie->id_customer)); 
     if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, (intval($cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $from))) 
      $smarty->assign('confirmation', 1); 
     else 
      $errors[] = Tools::displayError('an error occurred while sending message'); 
    } 
} 

$email = Tools::safeOutput(Tools::getValue('from', ((isset($cookie) AND isset($cookie->email) AND Validate::isEmail($cookie->email)) ? $cookie->email : ''))); 
$smarty->assign(array(
    'errors' => $errors, 
    'email' => $email 
)); 

$smarty->display(_PS_THEME_DIR_.'contact-form.tpl'); 
include(dirname(__FILE__).'/footer.php'); 

?> 

接下來是文件接觸form.tpl代碼: -

{capture name=path}{l s='Contact'}{/capture} 

{include file=$tpl_dir./breadcrumb.tpl} 



<h2>{l s='Contact us'}</h2> 



{if isset($confirmation)} 

    <p>{l s='Your message has been successfully sent to our team.'}</p> 

    <ul class="footer_links"> 

     <li><a href="{$base_dir}"><img class="icon" alt="" src="{$img_dir}icon/home.gif"/></a><a href="{$base_dir}">{l s='Home'}</a></li> 

    </ul> 

{else} 

    <p class="bold">{l s='For questions about an order or for information about our products'}.</p> 

    {include file=$tpl_dir./errors.tpl} 

    <form action="{$request_uri|escape:'htmlall':'UTF-8'}" method="post" class="std"> 

     <fieldset> 

      <h3>{l s='Send a message'}</h3> 

      <p class="select"> 

       <label for="id_contact">{l s='Subject'}</label> 

       <select id="id_contact" name="id_contact" onchange="showElemFromSelect('id_contact', 'desc_contact')"> 

        <option value="0">{l s='-- Choose --'}</option> 

       {foreach from=$contacts item=contact} 

        <option value="{$contact.id_contact|intval}" {if isset($smarty.post.id_contact) && $smarty.post.id_contact == $contact.id_contact}selected="selected"{/if}>{$contact.name|escape:'htmlall':'UTF-8'}</option> 

       {/foreach} 

       </select> 

      </p> 

      <p id="desc_contact0" class="desc_contact">&nbsp;</p> 

     {foreach from=$contacts item=contact} 

      <p id="desc_contact{$contact.id_contact|intval}" class="desc_contact" style="display:none;"> 

      <label>&nbsp;</label>{$contact.description|escape:'htmlall':'UTF-8'}</p> 

     {/foreach} 

     <p class="text"> 

      <label for="email">{l s='E-mail address'}</label> 

      <input type="text" id="email" name="from" value="{$email}" /> 

     </p> 

     <p class="textarea"> 

      <label for="message">{l s='Message'}</label> 

      <textarea id="message" name="message" rows="7" cols="35">{if isset($smarty.post.message)}{$smarty.post.message|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea> 

     </p> 

     <p class="submit"> 

      <input type="submit" name="submitMessage" id="submitMessage" value="{l s='Send'}" class="button_large" /> 

     </p> 

    </fieldset> 

</form> 

{/if} 

沒有人有任何想法,我怎麼可以調整這個聯絡表格爲了分配我選擇的發件人地址(例如[email protected]),希望這封電子郵件表格能夠爲我開始工作。如果這個'from'地址存儲在其他地方,任何人都可以看到它的存儲位置或代碼中引用的位置?

回答

0

如果這個'from'地址存儲在其他地方,任何人都可以看到它可能存儲在哪裏或它在代碼中引用的位置嗎?

我不能從碼告訴我們,但我強烈的猜測是這個文件:

include(dirname(__FILE__).'/config/config.inc.php'); 

編輯:

if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', 
array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), 
$contact->email, $contact->name, $from, (intval($cookie->id_customer) ? 
$customer->firstname.' '.$customer->lastname : $from))) 

我不能近距離地觀察正確的代碼現在,但替代要麼

'{email}' => $_POST['from'] 

$from 

通過

'{email}' => 'whatever_you_want' 

'whatever_you_want' 

威力做的伎倆。

+0

當前的「發件人」地址實際上不是[email protected]的形式。我認爲它是在用戶在提交表單之前輸入他們的電子郵件地址時輸入的數據自動生成的。但是我會看看config.inc.php,看看裏面有什麼。 – nitbuntu 2010-02-11 17:23:41

+0

的一點是,我想要的「從」地址是我事先指定的東西(如[email protected]),我想通過用戶輸入的地址是「回覆地址」我會接受的他們發送的郵件。 – nitbuntu 2010-02-11 17:25:15

+0

@nitbuntu查看我更新的答案。 – 2010-02-11 17:30:30