hi,
i am doing mailing concept in php. In this admin side admin send mails to users with attached files. but i wrote normal code for email without attachments. how to write code for attachfiles.
muralibobby2015 17 Posting Pro
venkat0904 1 Junior Poster
show us the code u r using for sending mail... r u using some predefined class such as phpmailer or something? we can suggest u better after having a look on ur code
hi,
i am doing mailing concept in php. In this admin side admin send mails to users with attached files. but i wrote normal code for email without attachments. how to write code for attachfiles.
muralibobby2015 17 Posting Pro
show us the code u r using for sending mail... r u using some predefined class such as phpmailer or something? we can suggest u better after having a look on ur code
definately! actually i am using' class.phpmailer.php' in this.
$mail->From = $_POST[email];
$mail->FromName = $_POST[name];
$mail->AddAddress($_POST[friendemail]);
/* $mail->AddCC($resNewsUsers["emailid"]);
$mail->AddBCC($resNewsUsers["emailid"]);*/
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $sub;
$mail->Body = $msg;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
$mail->Send();
venkat0904 1 Junior Poster
ohhh then its pretty simple...
phpmailer provides you with an option to send email attachments...
just upload the attachment file using input type="file"
and add this line to your code
$mail->AddAttachment("path_to_uploaded_file, file_name");
Do remember to check the file type before uploading it to ur system or else u can end up uploading some malicious files that can even crash ur machine..
Hope this helps.. Cheers!!!
definately! actually i am using'
class.phpmailer.php' in this.$mail->From = $_POST[email]; $mail->FromName = $_POST[name]; $mail->AddAddress($_POST[friendemail]); /* $mail->AddCC($resNewsUsers["emailid"]); $mail->AddBCC($resNewsUsers["emailid"]);*/ $mail->IsHTML(true); // set email format to HTML $mail->Subject = $sub; $mail->Body = $msg; $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; $mail->Send();
Edited by venkat0904 because: n/a
network18 15 Practically a Master Poster
Do you have the function in your class-
function AttachAll() {
// Return text of body
$mime = array();
// Add all attachments
for($i = 0; $i < count($this->attachment); $i++)
{
// Check for string attachment
$bString = $this->attachment[$i][5];
if ($bString)
$string = $this->attachment[$i][0];
else
$path = $this->attachment[$i][0];
$filename = $this->attachment[$i][1];
$name = $this->attachment[$i][2];
$encoding = $this->attachment[$i][3];
$type = $this->attachment[$i][4];
$disposition = $this->attachment[$i][6];
$cid = $this->attachment[$i][7];
$mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
$mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
if($disposition == "inline")
$mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
$disposition, $name, $this->LE.$this->LE);
// Encode as string attachment
if($bString)
{
$mime[] = $this->EncodeString($string, $encoding);
if($this->IsError()) { return ""; }
$mime[] = $this->LE.$this->LE;
}
else
{
$mime[] = $this->EncodeFile($path, $encoding);
if($this->IsError()) { return ""; }
$mime[] = $this->LE.$this->LE;
}
}
$mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
return join("", $mime);
}
network18 15 Practically a Master Poster
call this function to attach -
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;
}
muralibobby2015 17 Posting Pro
$sub = "".$name." invites you to www.murali.com";
$msg = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td height='8'></td>
</tr>
<tr>
<td style='font-family:Verdana; font-size:12px; font-weight:normal; color:#000000' align='left'>
<br>
<p>".$transl2." </p><br>
<table align='center'>
<tr>
<td>username</td>
<td><input type='text' name='username'></td>
</tr>
<tr>
<td>password</td>
<td><input type='password' name='password'></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='submit' value='submit'></td>
</tr>
</table>
<br>
<a href=".$sitename.">Click here</a> to View My Own Blog. </td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td align='left' style='font-family:Verdana; font-size:12px; font-weight:bold; color:#47493F'>Regards,<br>
murali.
</td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='4'></td>
</tr>
</table>";
$msg = stripslashes($msg);
the above code which is in table that table is send to users by email. in that user fills that values and submit the form. then how i will get the values from that .
venkat0904 1 Junior Poster
when phpmailer is working fine for you wy dont u stick with it...
just give a shot to what i suggested..
$sub = "".$name." invites you to www.murali.com"; $msg = "<table width='100%' border='0' cellspacing='0' cellpadding='0'> <tr> <td height='8'></td> </tr> <tr> <td style='font-family:Verdana; font-size:12px; font-weight:normal; color:#000000' align='left'> <br> <p>".$transl2." </p><br> <table align='center'> <tr> <td>username</td> <td><input type='text' name='username'></td> </tr> <tr> <td>password</td> <td><input type='password' name='password'></td> </tr> <tr> <td> </td> <td><input type='submit' name='submit' value='submit'></td> </tr> </table> <br> <a href=".$sitename.">Click here</a> to View My Own Blog. </td> </tr> <tr> <td height='8'></td> </tr> <tr> <td height='8'></td> </tr> <tr> <td height='8'></td> </tr> <tr> <td align='left' style='font-family:Verdana; font-size:12px; font-weight:bold; color:#47493F'>Regards,<br> murali. </td> </tr> <tr> <td height='8'></td> </tr> <tr> <td height='8'></td> </tr> <tr> <td height='4'></td> </tr> </table>"; $msg = stripslashes($msg);
the above code which is in table that table is send to users by email. in that user fills that values and submit the form. then how i will get the values from that .
muralibobby2015 17 Posting Pro
when phpmailer is working fine for you wy dont u stick with it...
just give a shot to what i suggested..
if($_POST)
{
/////////////////////////////////////////////////////////////////////////////////////////////
/////// send invitation to friends /////////
///////////////////////////////////////////////////////////////////////////////////////////
$sitename="http://localhost/murali/";
//this subject will be visible only for you
$sub = "".$name." invites you to www.murali.com";
$msg = "<html><head>
<script language='javascript'>
function page()
{
alert('aaaa');
if(window.document.formz.username.value=='')
{
alert('enter username');
window.document.formz.username.focus();
return false;
}
if(window.document.formz.password.value=='')
{
alert('enter password');
window.document.formz.password.focus();
return false;
}
else
{
window.document.formz.action='http://localhost/murali/index.php?ok=ok';
return true;
}
}
</script>
</head>
<body>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td height='8'></td>
</tr>
<tr>
<td style='font-family:Verdana; font-size:12px; font-weight:normal; color:#000000' align='left'>
<br>
<p>".$transl2." </p><br>
<form name='formz' action='' method='post' onsubmit='return page();'>
<table align='center'>
<tr>
<td>username</td>
<td><input type='text' name='username'></td>
</tr>
<tr>
<td>password</td>
<td><input type='password' name='password'></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='submit' value='submit'></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td align='left' style='font-family:Verdana; font-size:12px; font-weight:bold; color:#47493F'>Regards,<br>
murali.
</td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='8'></td>
</tr>
<tr>
<td height='4'></td>
</tr>
</table></body>
</html>";
$msg = stripslashes($msg);
//echo $msg;
// echo "<br>";
// echo exit;
//include("includes/class.smtp.php");
//include("includes/constants.php");
$SmtpAuth = 1; // 1 For IsSMTP() and 0 For IsMail()
$mail = new PHPMailer();
//$mail->IsMail();
if($SmtpAuth == 0)
{
$mail->IsMail();
}
else
{
$mail->IsSMTP();
$mail->Host = ""; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
} // set mailer to use SMTP
$mail->From = $_POST[email];
$mail->FromName = $_POST[name];
$mail->AddAddress($_POST[friendemail]);
/* $mail->AddCC($resNewsUsers["emailid"]);
$mail->AddBCC($resNewsUsers["emailid"]);*/
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $sub;
$mail->Body = $msg;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
$mail->Send();
$send=1;
ok...i am getting mails. but problem is if admin sends registration form in mail. then user fill that form clicks submit button. then javascripts calling. up to there every thing is fine. the overall prblm is rdirecting to page from personal mail page(example:gmail). when i am submit the form alerting like "You are submitting information to an external page.
Are you sure?" then we press ok button that zz redicting blank page.
muralibobby2015 17 Posting Pro
give any suggestions. i put a form in mail body. that form is registration form. when i am clicking submit button which is in our mail then it redirects to google. that is the problem. any body give suggetions
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.