PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : E-Mail versenden mit anhang per SMTP wie?



SUNZ
10.06.2010, 08:29
E-Mail versenden mit anhang per SMTP wie?
Hallo,

Ich habe ein script mit dem ich E-Mails versenden kann. nun möchte ich das die E-Mail einen Anhang hat aus einem bestimmt ordner auf meinem Server.


Hier mal das Script was ich schon habe:


function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {

$smtpServer = "mail.gmx.net";
$port = "25";
$timeout = "45";
$username = "sales@mydomain.com";
$password = "XXXXXXX";
$localhost = "127.0.0.1";
$newLine = "\r\n";
$secure = 0;


//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect)) {
$output = "Failed to connect: $smtpResponse";
echo $output;
return $output;
}
else {
$logArray['connection'] = "<p>Connected to: $smtpResponse";
echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}



$err=0;
$err_msg="";

echo $err_msg;
if($err<=0) {
$from="sales@mydomain.com";
$namefrom="Admin";
$to = "internal_user@mydomain.com";
$nameto = "User";
$subject = "Das ist der Betreff";
$message = "Hi ich bin der Text";
// this is it, lets send that email!
authgMail($from, $namefrom, $to, $nameto, $subject, $message);
}
else {
echo "<p /> This form was not filled out correctly, please correct any mistakes.";
}


Ich möchte nun das ich mit diesem Script auch noch einen Anhang versenden kann.

Weis jemand wie ich das mache.

Mein Smtp hoster ist mail.gmx.net



Mit freundlichen grüßen

albahacker
10.06.2010, 08:38
am besten ist du versendest deine emails per programm siehe atomic mailer dort kannst du dann ohne probleme einen anhang machen

bayer
10.06.2010, 08:41
toll, albahacker...

@Sunz:

PHP: Sending Email (Text/HTML/Attachments) (http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment)

http://zainal.wordpress.com/2007/01/10/sending-email-attachments-in-php-using-phpmailer-class/

SUNZ
10.06.2010, 08:52
nochmal so neben bei das script wird auf einem server geladen weil es da kein MAil(); funktioniert deswegen smtp.


Ich sitze jetzt schon seit 3 tagen dran und deswegen melde ich mich hier.
weil ich es nicht gebacken bekomme es in das script einzufügen. es wäre super wenn einer das machen könnte. kann leider nichts bieten auser ein thx

bayer
10.06.2010, 09:03
die phpmailer-Klasse benutzt doch garkeine mail(); funktion O_o

Worx International Inc. (http://phpmailer.sourceforge.net)


1:<?php
2: require("class.phpmailer.php");
3: $mail = new PHPMailer();
4:
5: $mail->IsSMTP(); // send via SMTP
6: $mail->Host = "smtp1.site.com;smtp2.site.com"; // SMTP servers
7: $mail->SMTPAuth = true; // turn on SMTP authentication
8: $mail->Username = "user"; // SMTP username
9: $mail->Password = "pass"; // SMTP password
10:
11: $mail->From = "from@email.com";
12: $mail->FromName = "Mailer";
13: $mail->AddAddress("josh@site.com","Josh Adams");
14: $mail->AddAddress("ellen@site.com"); // optional name
15: $mail->AddReplyTo("info@site.com","Information");
16:
17: $mail->WordWrap = 50; // set word wrap
18: $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
19: $mail->AddAttachment("/tmp/image.jpg", "new.jpg");
20: $mail->IsHTML(true); // send as HTML
21:
22: $mail->Subject = "Here is the subject";
23: $mail->Body = "This is the <b>HTML body</b>";
24: $mail->AltBody = "This is the text-only body";
25:
26: if(!$mail->Send())
27: {
28: echo "Message was not sent <p>";
29: echo "Mailer Error: " . $mail->ErrorInfo;
30: exit;
31: }
32:
33: echo "Message has been sent";
34: ?>

SUNZ
10.06.2010, 09:12
ich will mein script behalten.

also wie mache ich es mit meinem script?

bayer
10.06.2010, 09:50
Sorry, wenn ich das jetzt so sage, aber ein wenig Eigeninitiative musst du schon zeigen. Du hast von mir alles bekommen, was du für dein Vorhaben brauchst, musst es nurnoch zusammenfrickeln. Wenn du das nicht kannst, lass dein Vorhaben bleiben und lern erstmal PHP...

Obwohl, das zusammenzufügen... Dazu braucht man nichmal nen IQ von 90.

SUNZ
10.06.2010, 10:06
ja super aber ich kann es eben nicht so perfekt.

ich bekomme es nicht hin deswegen frag ich in einem forum nach.
deswegen gibt es foren!