在PHP中合并邮件的两个文本框值

时间:2013-10-06 08:17:40

标签: php opencart

您好我正在编辑我的opencart网站。 我添加了一个新的文本框,他们需要输入一个联系号码。

<b>Contact Number:</b><br />    
<input type="text" name="number" />

<b><?php echo $entry_enquiry; ?></b><br />
<textarea name="enquiry" cols="40" rows="10" style="width: 99%;"><?php echo $enquiry; ?></textarea>

这是获取文本框的代码:

if (isset($this->request->post['number'])) {
    $this->data['number'] = $this->request->post['number'];
} else {
    $this->data['number'] = '';
}

if (isset($this->request->post['enquiry'])) {
    $this->data['enquiry'] = $this->request->post['enquiry'];
} else {
    $this->data['enquiry'] = '';
}

我目前遇到问题,因为我需要结合号码和查询。两个组合的文本框将是我邮件的setText。

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
    $mail = new Mail();
    $mail->protocol = $this->config->get('config_mail_protocol');
    $mail->parameter = $this->config->get('config_mail_parameter');
    $mail->hostname = $this->config->get('config_smtp_host');
    $mail->username = $this->config->get('config_smtp_username');
    $mail->password = $this->config->get('config_smtp_password');
    $mail->port = $this->config->get('config_smtp_port');
    $mail->timeout = $this->config->get('config_smtp_timeout');             
    $mail->setTo($this->config->get('config_email'));
    $mail->setFrom($this->request->post['email']);
    $mail->setSender($this->request->post['name']);
    $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
    $mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
    $mail->send();

我能得到任何帮助吗?

2 个答案:

答案 0 :(得分:1)

也许你想要这样的东西:

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
    $enquiry_and_contact = $this->request->post['enquiry'] . "\n\n"; 
    $enquiry_and_contact .= "Contact: " . $this->request->post['number']; 

    $mail = new Mail();
    $mail->protocol = $this->config->get('config_mail_protocol');
    $mail->parameter = $this->config->get('config_mail_parameter');
    $mail->hostname = $this->config->get('config_smtp_host');
    $mail->username = $this->config->get('config_smtp_username');
    $mail->password = $this->config->get('config_smtp_password');
    $mail->port = $this->config->get('config_smtp_port');
    $mail->timeout = $this->config->get('config_smtp_timeout');             
    $mail->setTo($this->config->get('config_email'));
    $mail->setFrom($this->request->post['email']);
    $mail->setSender($this->request->post['name']);
    $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
    $mail->setText(strip_tags(html_entity_decode($enquiry_and_contact, ENT_QUOTES, 'UTF-8')));
    $mail->send();
}

答案 1 :(得分:0)

使用连接运算符( .

更改此

$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));

$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'].$this->request->post['number'], ENT_QUOTES, 'UTF-8')));

修改

$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry']." ".$this->request->post['number'], ENT_QUOTES, 'UTF-8')));