I have looked and looked for an answer to this and cannot find anything so If this already has an answer please let me know.
I am using PHPMailer and using SMTP to send emails with files attached.
Here is my Code:
<?php
/**
* SMTP Server Using Yahoo To Upload Files And Submit, Port 465 Using SSL
*/
require_once('PHPMailer/PHPMailerAutoload.php');
define('GUSER', '****@yahoo.com'); // Yahoo username
define('GPWD', '*****'); // Yahoo password
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
// First handle the upload
// Don't trust provided filename - same goes for MIME types
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// Upload handled successfully
// Now create a message
// This should be somewhere in your include_path
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.mail.yahoo.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->setFrom('****@yahoo.com', 'Sent File');
$mail->addAddress('****@****.com');
$mail->Subject = 'Test File';
$mail->msgHTML("My message body");
// Attach the uploaded file
$mail->addAttachment($uploadfile, $_FILES['userfile']['name']);
if (!$mail->send()) {
$msg = "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg = "Message sent!";
}
} else {
$msg = 'Failed to move file to ' . $uploadfile;
}
}
?>
<?php if (empty($msg)) { ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000"> Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
<?php } else {
echo $msg;
} ?>
When I Use This on my local lamp server it works perfectly, However when I use it on my Yahoo Hosting Server, I get this error: SMTP ERROR: Failed to connect to server: Permission denied (13)
Looking into what that error represents, It sounds like the problem and solution has to do with the httpd_can_sendmail & httpd_can_network_connect Settings. It looks like they need to be activated. Source: http://gistpages.com/2013/09/14/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix
My problem is that with Yahoo, I cannot access a terminal to change these settings. Does anyone know of any other way to change these settings without having access to a linux terminal of the hosting server?
Thanks P.S I would not recommend using yahoo as a website hosting provider EVER to anyone!