Need help with sending a contact form with an e-mail
Posted: Fri Nov 09, 2007 10:01 am
I am creating a send form with several fields: Name, Phone, E-mail, Topic, Comments and Send File. I have no problem sending the first five fields (they got received at the e-mail account without problems) but so far I couldn't figure out what is the problem with the Send File one. Could anyone find the problem? Here is the code:
Code: Select all
<?php
if($_POST['IsPost']==1)
{
send_mail5($_POST);
}
?>
function send_mail5($data)
{
require_once ( CLASSES_PATH.'/phpmailer/class.phpmailer.php' );
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "localhost"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "site@mysite.com"; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
//ini_set( 'include_path', $_SERVER['DOCUMENT_ROOT'].'/candoit/smarty/libs/' );
$mail->From = 'site@mysite.com';
$mail->FromName = 'Nuevos Pedidos de Trabajo';
$to_address="rrhh@mysite.com";
$to_name="Admin";
$mail->AddAddress($to_address, $to_name);
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/mail/".$data['archivo']);
//echo WEB_PATH."main/".$data['mail'];exit();
//$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/documents/quotation".$data['id_quotation'].".pdf");
$mail->IsHTML(true); // send as HTML
$subject=$data['subject'];
$message = '
<html>
<head>
</head>
<body>
<table>
<tr>
<td>Name:</td><td>'.$data['name'].'</td>
</tr>
<tr>
<td>Phone:</td><td>'.$data['phone'].'</td>
</tr>
<tr>
<td>E-mail:</td><td>'.$data['email'].'</td>
</tr>
<tr>
<td>Comments:</td><td>'.$data['coments'].'</td>
</tr>
</table>
</body>
</html>
';
$mail->Subject = $subject;
$mail->Body = $message;
//$mail->AltBody = $text_message;
//echo $mail->Subject;
//echo $mail->Body;exit();
if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
function AddAttachment($path, $name = "", $encoding = "base64",
$type = "application/octet-stream") {
if(!@is_file($path))
{
$this->SetError($this->Lang("file_access") . $path);
return false;
}
$filename = basename($path);
if($name == "")
$name = $filename;
$cur = count($this->attachment);
$this->attachment[$cur][0] = $path;
$this->attachment[$cur][1] = $filename;
$this->attachment[$cur][2] = $name;
$this->attachment[$cur][3] = $encoding;
$this->attachment[$cur][4] = $type;
$this->attachment[$cur][5] = false; // isStringAttachment
$this->attachment[$cur][6] = "attachment";
$this->attachment[$cur][7] = 0;
return true;
}
<form action="" method="post" enctype="multipart/form-data" name="contact" style="padding-top:10px;">
<input type="hidden" name="IsPost" value="1" />
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>*Nombre y Apellidos</td><td style="padding-top:5px;"><input type="text" name="name" size="30"></td>
</tr>
<tr>
<td>*Numero de Telefono</td><td style="padding-top:5px;"><input type="text" name="phone" size="30"></td>
</tr>
<tr>
<td>E-mail</td><td style="padding-top:5px;"><input type="text" name="email" size="30"></td>
</tr>
<tr>
<td>Asunto</td><td style="padding-top:5px;"><input type="text" name="subject" size="30"></td>
</tr>
<tr>
<td>Comentarios</td><td style="padding-top:5px;"><textarea name="coments" rows="10" cols="25" style="width:200px;"></textarea></td>
</tr>
<tr>
<td>Send File</td>
<td style="padding-top:5px;"><input type="file" name="archivo" id="archivo" /></td>
</tr>
<tr>
<td colspan="2" style="padding-left:30px;"><input type="button" class="go-btn" onclick="document.contact.submit();" ></td>
</tr>
</table>
</form>