Problems, need help? Have a tip or advice? Post it here.
14 posts Page 1 of 2
Hi all

Need help in the form mail script. I have built a form using the emailex.php since the form had a attachment.

Everything is working perfectly on our test server, however on the final server the hosting company requires smtp authentication, outgoing mail server, port, email id & password.

What is the solution and where can I put in the authentication script.

Alok
I posted an answer here:
viewtopic.php?f=4&t=8675

works with Gmail, but you can just ask your company to give you the details required and it's all the same.

Opening an account with Gmail is a good solution too.
PaoloE beat me to it :)
I was in the process of making the same suggestion.

Alok, Both cms:send_mail and emailex use the standard PHP mail() function which doesn't use SMTP authentication. You'll have to consider Paolo's solution for that.
Hi

Got the mail thing working. Given below is the script

<cms:form action='' method='post' enctype="multipart/form-data" id='enquiry_form'>

<cms:if k_success >
<h3>Thank you for contacting us!</h3>
<cms:capture into='my_message'>
The following is an email sent by a visitor to your site:
Company Name: <cms:show frm_companyname />
Contact Person: <cms:show frm_contactperson />
Phone: <cms:show frm_phone />
Email: <cms:show frm_email />
Type of Enquiry: <cms:show frm_enquirytype />
Estimate qty: <cms:show frm_qty />
Requirements: <cms:show frm_requirements />
How to contact: <cms:show frm_contacttype />
Design width: <cms:show frm_designwidth />
Design height: <cms:show frm_designheight />
Measurements: <cms:show frm_measurements />
Fabric: <cms:show frm_fabric />
Location: <cms:show frm_location />
Delivery date: <cms:show frm_deliveryday />
</cms:capture>

<cms:php>
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.xxx.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@domain.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail-> SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to


$mail->addAddress('mymail@domain.com'); // Add a recipient
$mail->addReplyTo('<cms:show frm_email />', '<cms:show frm_name />');

$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML

$mail->From = '<cms:show frm_email />';
$mail->FromName = '<cms:show frm_name />';
$mail->Subject = 'Enquiry from your site';
$mail->Body = '<cms:show my_message />';


if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
</cms:php>

</cms:if>


However 2 more issues have cropped up.

1. Attachment thing is not working (given below is the code)

<input type="file" name="my_file_ex"><br />
<cms:input
type="hidden"
name="my_file"
required='1'
validator='EmailEx::validate=max_size:512&allowed_ext:jpeg,jpg,gif,png,txt'
value='1' /> </td>
<cms:if k_error_my_file_ex>

2. Previously the mail used to come in a proper format now all the fields appear in a single line
1. Attachment thing is not working (given below is the code)

<input type="file" name="my_file_ex"><br />
<cms:input
type="hidden"
name="my_file"
required='1'
validator='EmailEx::validate=max_size:512&allowed_ext:jpeg,jpg,gif,png,txt'
value='1' /> </td>
<cms:if k_error_my_file_ex>

For others chancing upon this thread, Alok is using the method described in the following thread for sending attachments with emails -
viewtopic.php?f=8&t=6959

@alok
I've added the PHP required to handle attachments in your code. The revised code is as follows -
Code: Select all
<cms:php>
    require 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;

    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'mail.xxx.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'mymail@domain.com'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail-> SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587; // TCP port to connect to


    $mail->addAddress('mymail@domain.com'); // Add a recipient
    $mail->addReplyTo('<cms:show frm_email />', '<cms:show frm_name />');

    $mail->WordWrap = 50; // Set word wrap to 50 characters
    $mail->isHTML(true); // Set email format to HTML

    $mail->From = '<cms:show frm_email />';
    $mail->FromName = '<cms:show frm_name />';
    $mail->Subject = 'Enquiry from your site';
    $mail->Body = '<cms:show my_message />';

    // do we have attachments           
    global $__FILES;       
    $arr_uploads = array();           
    if( is_array($__FILES) )  $arr_uploads = $__FILES;                       
    foreach( $arr_uploads as $upload ){               
        $mail->addAttachment( $upload['tmp_name'], basename( $upload['name'] ) );           
    }

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
</cms:php>
where the portion relevant to attachments is -
Code: Select all
    // do we have attachments            
    global $__FILES;       
    $arr_uploads = array();           
    if( is_array($__FILES) )  $arr_uploads = $__FILES;                       
    foreach( $arr_uploads as $upload ){               
        $mail->addAttachment( $upload['tmp_name'], basename( $upload['name'] ) );           
    }

Hope this helps.
@kk So this is the only way of having a file attached to a sent form?


I would need it as part of the registration process for the members module, that is why I am asking :)
@madebym, for 'members' module this seems to be the only available option, I'm afraid.
For 'extended-users', however, we could use 'securefile' regions for the attachments during registration.
Thanks for the info KK. The thing is that I already have 'members' module setup. Is it much work editing the code to use 'extended-users' instead of 'members' ? I am a bit short on time with this website :(


p.s. Also, is it possible to auto-populate the checkout fields in the cart by using each registered member info? That would be really handy :)
Is it much work editing the code to use 'extended-users' instead of 'members' ?
If you already have it working with members module I wouldn't suggest trying to port it to extended-users. That would be too much unnecessary work at this stage.

is it possible to auto-populate the checkout fields in the cart by using each registered member info?
Checkout template is a normal Couch managed template so shouldn't be difficult to fetch data for the logged-in member and use it in there. Give it a try.
Thanks @KK Hopefully everything will work nicely :)
14 posts Page 1 of 2