我正在尝试将图片附加到联系表单发送的电子邮件中,这样我的客户就可以看到它是哪个产品,它是一个汽车经销商,所以有时他会有几个同名车辆。
到目前为止我所做的是有一个隐藏的输入字段,将文件名发布到表单处理程序,我的问题是如何处理图像,以便可以将其视为签名或显示电子邮件无需打开它。
在将数据放入$Bodymessage
之前,我是否打电话给数据库选择图片名称已发布的图片并预定义目的地?或者可以有其他一些巧妙的伎俩吗?
答案 0 :(得分:0)
我建议这样的事情
$to = 'to@example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['from_email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['to_email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img src="imag_url_not_path">';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
答案 1 :(得分:0)
This is my form Handler:
<?php
$stocknr = $_POST['snr'];
$EmailFrom = $_POST['visitormail'];
$EmailTo = "someone@email.com";
$Subject = "Details -"." $stocknr";
$Name = Trim(stripslashes($_POST['visitor']));
$Tel = Trim(stripslashes($_POST['visitortel']));
$Cell = Trim(stripslashes($_POST['visitorcel']));
$Email = Trim(stripslashes($_POST['visitormail']));
$Message = Trim(stripslashes($_POST['notes']));
$trans = $_POST['trans'];
$fuel = $_POST['fuel'];
$desc = $_POST['desc'];
$year = $_POST['year'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$price = $_POST['price'];
$counter = $_POST['counter'];
$title = $_POST['title'];
$uppic = $_POST['pic'];
// validation
$validationOK=true;
if (!$validationOK)
{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
$con=mysqli_init();
if (!$con)
{
die("mysqli_init_failed");
}
if (!mysqli_real_connect($con,$servername,$dbusername,$dbpassword,$dbname))
{
die("Connect Error: " . mysqli_connect_error());
}
$query = "SELECT pic, stocknr FROM stock WHERE stocknr = '$stocknr'";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($result);
$pic = $row['pic'];
// prepare email body text
$Body = '<html><body>';
$Body .= "Att Saayman Motors";
$Body .= "\n";
$Body .= "\n";
$Body .= "Please follow up on the following lead below generated by Details
- "."$stocknr";
$Body .= "\n";
$Body .= "\n";
$body .= "<p class='header'>Requested Followup Information</p>";
$Body .= "\n";
$Body .= "\n";
$Body .= "Interested Person Details";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "\n";
$Body .= "Cell: ";
$Body .= $Cell;
$Body .= "\n";
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$Body .= "\n";
$Body .= "Vehicle Information";
$Body .= "\n";
$Body .= "\n";
$Body .= "Details :";
$Body .= $title;
$Body .= "\n";
$Body .= "\n";
$Body .= "Stocknr: ";
$Body .= $stocknr;
$Body .= "\n";
$Body .= "\n";
$Body .= "Price: ";
$Body .= "\n";
$Body .= "\n";
$Body .= "R ";
$Body .= $price;
$Body .= "\n";
$Body .= "\n";
$Body .= "";
$Body .= '<img src="http://www.saaymanmotors.co.za/upload/$pic">';
$Body .= '</body></html>';
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
这是我的联系表格
<form name="contactform" method="post" action="/contactengine.php">
<?php
$sqli = "SELECT trans, fuel, description, counter, year, brand, model,
stocknr, price, pic FROM stock WHERE stocknr = '$stocknr'";
// Perform Query
$resulti = mysqli_query($con,$sqli);
$row = mysqli_fetch_assoc($resulti);
$trans = $row['trans'];
$fuel = $row['fuel'];
$desc = $row['description'];
$year = $row['year'];
$brand = $row['brand'];
$model = $row['model'];
$price = $row['price'];
$counter = $row['counter'];
$picloc = $row['pic'];
$title = "$year "."$brand "."$model";
$trans = $trans;
$fuel = $fuel;
$desc = $desc;
$year = $year;
$brand = $brand;
$model = $model;
$price = $price;
$counter = $counter;
$picloc = $picloc;
$stocknr = $stocknr;
?>
<input type="hidden" name="snr" value="<?php echo $stocknr ;?>" />
<input type="hidden" name="trans" value="<?php echo $trans ;?>" />
<input type="hidden" name="fuel" value="<?php echo $fuel ;?>" />
<input type="hidden" name="desc" value="<?php echo $desc ;?>" />
<input type="hidden" name="title" value="<?php echo $title ;?>" />
<input type="hidden" name="brand" value="<?php echo $brand ;?>" />
<input type="hidden" name="year" value="<?php echo $year ;?>" />
<input type="hidden" name="price" value="<?php echo $price ;?>" />
<input type="hidden" name="counter" value="<?php echo $counter ;?>" />
<input type="hidden" name="pic" value="<?php echo $picloc ;?>" />
<table width="320px">
<tr>
<td valign="top">
<label class="form_header" for="visitor">Name *</label>
<table>
<tr>
<td valign="top">
<input class="form_input" type="text" name="visitor" maxlength="50"
size="30">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<label class="form_header" for="visitorcel">Cellphone *</label>
<table>
<tr>
<td valign="top">
<input class="form_input" type="tel" name="visitorcel" maxlength="50"
size="30">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<label class="form_header" for="visitormail">Email Address *</label>
<table>
<tr>
<td valign="top">
<input class="form_input" type="email" name="visitormail" maxlength="80"
size="30">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<label class="form_header" for="visitortel">Telephone Number</label>
<table>
<tr>
<td valign="top">
<input class="form_input" type="tel" name="visitortel" maxlength="30"
size="30">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<label class="form_header" for="notes">Message *</label>
<table>
<tr>
<td valign="top">
<textarea class="form_mes_input" name="notes" maxlength="1000" cols="25"
rows="6"></textarea>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100" style="text-align:left">
<input type="submit" class="button submit_button" value="Submit">
</td>
</tr>
</table>
</form>