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:
[php]
function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
$smtpServer = „mail.gmx.net“;
$port = „25“;
$timeout = „45“;
$username = „[email protected]“;
$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‘] = " Connected to: $smtpResponse";
echo " connection accepted
„.$smtpResponse.“ Continuing ";
}
//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: " . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray[‚mailfromresponse‘] = „$smtpResponse“;
//email to
fputs($smtpConnect, "RCPT 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 " . $newLine;
$headers .= "From: $namefrom " . $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 This form was not filled out correctly, please correct any mistakes.";
}
?>
[/php]
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